Exemple #1
0
 public IAsyncOperation <ColorFrameReader> OpenColorFrameReaderAsync(ReaderConfig config = ReaderConfig.Default)
 {
     return(Task.Run(async() =>
     {
         if (ColorReader == null)
         {
             if (Type == SensorType.NetworkClient)
             {
                 ColorReader = new ColorFrameReader(this, _networkClient, config);
             }
             else
             {
                 var colorSourceInfo = _sourceGroup.SourceInfos.FirstOrDefault(si => si.SourceKind == MediaFrameSourceKind.Color);
                 if (colorSourceInfo != null)
                 {
                     MediaFrameSource colorSource;
                     if (_mediaCapture.FrameSources.TryGetValue(colorSourceInfo.Id, out colorSource))
                     {
                         var colorMediaReader = await _mediaCapture.CreateFrameReaderAsync(colorSource);
                         ColorReader = new ColorFrameReader(this, colorMediaReader, config);
                     }
                 }
             }
         }
         await ColorReader?.OpenAsync();
         return ColorReader;
     }).AsAsyncOperation());
 }
Exemple #2
0
        public IAsyncAction CloseAsync()
        {
            return(Task.Run(async() =>
            {
                await BodyIndexReader?.CloseAsync();
                BodyIndexReader?.Dispose();
                BodyIndexReader = null;

                await BodyReader?.CloseAsync();
                BodyReader?.Dispose();
                BodyReader = null;

                await ColorReader?.CloseAsync();
                ColorReader?.Dispose();
                ColorReader = null;

                await DepthReader?.CloseAsync();
                DepthReader?.Dispose();
                DepthReader = null;

                AudioReader?.Close();
                AudioReader?.Dispose();
                AudioReader = null;

                _mediaCapture?.Dispose();
                _mediaCapture = null;

                _networkClient?.CloseConnection();
                _networkClient = null;

                _networkServer?.CloseConnection();
                _networkServer = null;
            }).AsAsyncAction());
        }
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Parses uncompressed image data
 /// </summary>
 /// <param name="readcolor">delegate function for reading a single color from the data</param>
 /// <param name="offset">the place to start reading</param>
 private void ParseUncompressed(ColorReader readcolor, int offset)
 {
     while (_tgadata.imageData.Length > r)
         readcolor(ref offset);
 }
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            /// <summary>
            /// Scans through image data if it has RLE compression
            /// </summary>
            /// <param name="readcolor">delegate function for reading a single color from the data</param>
            /// <param name="offset">the place to start reading</param>
            private void ParseRLE(ColorReader readcolor, int offset)
            {
                int imageStart = offset;
                while (offset < (_tgadata.imageData.Length + imageStart))
                {
                    if (r >= _tgadata.imageData.Length)
                    {
                        break;
                    }
                    int id = _tgadata.rawData[offset++];

                    bool compressed = (id >= 128);
                    if (!compressed)
                    {
                        // we aren't compressed, so let's just read in the next id+1 bytes and call it a day.
                        ++id;
                        for (int i = 0; i != id; i++)
                        {
                            readcolor(ref offset);
                        }
                    }
                    else
                    {
                        // we're compressed. The next id-127 bytes are RLE
                        id -= 127;
                        for (int i = 0; i != id; i++)
                        {
                            int rleColor = offset;
                            readcolor(ref rleColor);
                        }
                        offset += _tgadata.bytesPerChannel;
                    }
                } // end while
            }
            private void ReadScanlines(MemoryStream dataStream, byte[] pixels, ColorReader colorReader, PngColorTypeInformation colorTypeInformation)
            {
                dataStream.Position = 0;

                int scanlineLength = CalculateScanlineLength(colorTypeInformation);

                int scanlineStep = CalculateScanlineStep(colorTypeInformation);

                byte[] lastScanline = new byte[scanlineLength];
                byte[] currScanline = new byte[scanlineLength];

                byte a = 0;
                byte b = 0;
                byte c = 0;

                int row = 0, filter = 0, column = -1;

                using (DeflaterInputStream compressedStream = new DeflaterInputStream(dataStream))
                {
                    int readByte = 0;
                    while ((readByte = compressedStream.ReadByte()) >= 0)
                    {
                        if (column == -1)
                        {
                            filter = readByte;

                            column++;
                        }
                        else
                        {
                            currScanline[column] = (byte)readByte;

                            if (column >= scanlineStep)
                            {
                                a = currScanline[column - scanlineStep];
                                c = lastScanline[column - scanlineStep];
                            }
                            else
                            {
                                a = 0;
                                c = 0;
                            }

                            b = lastScanline[column];

                            if (filter == 1)
                            {
                                currScanline[column] = (byte)(currScanline[column] + a);
                            }
                            else if (filter == 2)
                            {
                                currScanline[column] = (byte)(currScanline[column] + b);
                            }
                            else if (filter == 3)
                            {
                                currScanline[column] = (byte)(currScanline[column] + (byte)Math.Floor((double)((a + b) / 2)));
                            }
                            else if (filter == 4)
                            {
                                currScanline[column] = (byte)(currScanline[column] + PaethPredicator(a, b, c));
                            }

                            column++;

                            if (column == scanlineLength)
                            {
                                colorReader.ReadScanline(currScanline, pixels, _header);

                                column = -1;
                                row++;

                                Swap(ref currScanline, ref lastScanline);
                            }
                        }
                    }
                }
            }
            /// <summary>
            /// Decodes the image from the specified stream and sets
            /// the data to image.
            /// </summary>
            /// <param name="image">The image, where the data should be set to.
            /// Cannot be null (Nothing in Visual Basic).</param>
            /// <param name="stream">The stream, where the image should be
            /// decoded from. Cannot be null (Nothing in Visual Basic).</param>
            /// <exception cref="ArgumentNullException">
            ///     <para><paramref name="image"/> is null (Nothing in Visual Basic).</para>
            ///     <para>- or -</para>
            ///     <para><paramref name="stream"/> is null (Nothing in Visual Basic).</para>
            /// </exception>
            public Image Decode(Stream stream)
            {
                _stream = stream;
                _stream.Seek(8, SeekOrigin.Current);

                bool isEndChunckReached = false;

                PngChunk currentChunk = null;

                byte[] palette      = null;
                byte[] paletteAlpha = null;

                using (MemoryStream dataStream = new MemoryStream())
                {
                    while ((currentChunk = ReadChunk()) != null)
                    {
                        if (isEndChunckReached)
                        {
                            throw new Exception("Image does not end with end chunk.");
                        }

                        if (currentChunk.Type == PngChunkTypes.Header)
                        {
                            ReadHeaderChunk(currentChunk.Data);

                            ValidateHeader();
                        }
                        else if (currentChunk.Type == PngChunkTypes.Physical)
                        {
                            ReadPhysicalChunk(currentChunk.Data);
                        }
                        else if (currentChunk.Type == PngChunkTypes.Data)
                        {
                            dataStream.Write(currentChunk.Data, 0, currentChunk.Data.Length);
                        }
                        else if (currentChunk.Type == PngChunkTypes.Palette)
                        {
                            palette = currentChunk.Data;
                        }
                        else if (currentChunk.Type == PngChunkTypes.PaletteAlpha)
                        {
                            paletteAlpha = currentChunk.Data;
                        }
                        else if (currentChunk.Type == PngChunkTypes.Text)
                        {
                            ReadTextChunk(currentChunk.Data);
                        }
                        else if (currentChunk.Type == PngChunkTypes.End)
                        {
                            isEndChunckReached = true;
                        }
                    }

                    byte[] pixels = new byte[_header.Width * _header.Height * 4];

                    PngColorTypeInformation colorTypeInformation = _colorTypes[_header.ColorType];

                    if (colorTypeInformation != null)
                    {
                        ColorReader colorReader = colorTypeInformation.CreateColorReader(palette, paletteAlpha);

                        ReadScanlines(dataStream, pixels, colorReader, colorTypeInformation);
                    }
                    Image i = new Image(_header.Width, _header.Height);
                    int   indx = 0;
                    byte  r, g, b, a;
                    for (uint y = 0; y < i.Height; y++)
                    {
                        for (uint x = 0; x < i.Width; x++)
                        {
                            r = pixels[indx];
                            indx++;
                            g = pixels[indx];
                            indx++;
                            b = pixels[indx];
                            indx++;
                            a = pixels[indx];
                            indx++;
                            i.SetPixel(x, y, new Pixel(r, g, b, a));
                        }
                    }
                    pixels = null;
                    System.GC.Collect();
                    return(i);
                }
            }
Exemple #7
0
        protected override void CreateMenu()
        {
            try
            {
                #region Mainmenu
                Menu = MainMenu.AddMenu("UB" + player.Hero, "UBAddons.MainMenu" + player.Hero, "UB" + player.Hero + " - UBAddons - by U.Boruto");
                Menu.AddGroupLabel("General Setting");
                Menu.CreatSlotHitChance(SpellSlot.W, 60);
                Menu.AddGroupLabel("Misc");
                Menu.Add("UBAddons.Twitch.Recall.Q", new CheckBox("Enable Stealth Recall"));
                #endregion

                #region Combo
                ComboMenu = Menu.AddSubMenu("Combo", "UBAddons.ComboMenu" + player.Hero, "Settings your combo below");
                {
                    ComboMenu.CreatSlotCheckBox(SpellSlot.Q);
                    ComboMenu.CreatSlotCheckBox(SpellSlot.W);
                    ComboMenu.CreatSlotCheckBox(SpellSlot.E);
                    var logic    = ComboMenu.Add("UBAddons.Twitch.E.LogicBox", new ComboBox("E Logic", 1, "Only Kill Steal", "Killsteal Smart", "At stacks", "At stacks and enemy count"));
                    var slider   = ComboMenu.Add("UBAddons.Twitch.E.Slider", new Slider("Use E only more than {0} enemy has passive buff", 3, 1, 5));
                    var slider2  = ComboMenu.Add("UBAddons.Twitch.E.Slider2", new Slider("Killsteal immediately if more than {0} enemy around me", 3, 1, 5));
                    var checkbox = ComboMenu.Add("UBAddons.Twitch.E.CheckBox", new CheckBox("E + Passive Logic if enemy in turret"));
                    var tips     = ComboMenu.Add("UBAddons.Twitch.E.Tip", new Label(""));
                    switch (logic.CurrentValue)
                    {
                    case 0:
                    {
                        slider.IsVisible   = false;
                        slider2.IsVisible  = false;
                        checkbox.IsVisible = false;
                        tips.DisplayName   = "E immediately if can kill enemy";
                    }
                    break;

                    case 1:
                    {
                        slider.IsVisible   = true;
                        slider.DisplayName = "Killsteal immediately if more than {0} enemy/ally around me";
                        slider2.IsVisible  = false;
                        checkbox.IsVisible = true;
                        tips.DisplayName   = "Hold your E till and attack other target till you can double kill/ triple kill, but smart usage";
                    }
                    break;

                    case 2:
                    {
                        slider.IsVisible    = false;
                        slider2.IsVisible   = true;
                        slider2.MaxValue    = 6;
                        slider2.DisplayName = "At Stacks";
                        checkbox.IsVisible  = true;
                        tips.DisplayName    = "Use E immediately if any Enemy has enough stacks";
                    }
                    break;

                    case 3:
                    {
                        slider.IsVisible    = true;
                        slider2.IsVisible   = true;
                        slider2.MaxValue    = 6;
                        slider2.DisplayName = "At Stacks";
                        checkbox.IsVisible  = true;
                        tips.DisplayName    = "Use E immediately if enough Enemy has enough stacks";
                    }
                    break;

                    default:
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    }
                    logic.OnValueChange += delegate(ValueBase <int> sender, ValueBase <int> .ValueChangeArgs args)
                    {
                        switch (args.NewValue)
                        {
                        case 0:
                        {
                            slider.IsVisible   = false;
                            slider2.IsVisible  = false;
                            checkbox.IsVisible = false;
                            tips.DisplayName   = "E immediately if can kill enemy";
                        }
                        break;

                        case 1:
                        {
                            slider.IsVisible   = true;
                            slider2.IsVisible  = false;
                            slider.DisplayName = "Killsteal immediately if more than {0} enemy/ally around me";
                            checkbox.IsVisible = true;
                            tips.DisplayName   = "Hold your E till and attack other target till you can double kill/ triple kill, but smart usage";
                        }
                        break;

                        case 2:
                        {
                            slider.IsVisible    = false;
                            slider2.IsVisible   = true;
                            slider2.MaxValue    = 6;
                            slider2.DisplayName = "At Stacks";
                            checkbox.IsVisible  = false;
                            tips.DisplayName    = "Use E immediately if any Enemy has enough stacks";
                        }
                        break;

                        case 3:
                        {
                            slider.IsVisible    = true;
                            slider.DisplayName  = "Use E only more than {0} enemy has passive buff";
                            slider2.IsVisible   = true;
                            slider2.MaxValue    = 6;
                            slider2.DisplayName = "At Stacks";
                            checkbox.IsVisible  = false;
                            tips.DisplayName    = "Use E immediately if enough Enemy has enough stacks";
                        }
                        break;

                        default:
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        }
                    };
                    ComboMenu.CreatSlotCheckBox(SpellSlot.R);
                    ComboMenu.Add("UBAddons.Twitch.R.OutRange", new CheckBox("Use R if target out of R Range"));
                    ComboMenu.CreatSlotHitSlider(SpellSlot.R, 3, 1, 5);
                    ComboMenu.AddLabel("Only Use R out range if 90% can kill enemy");
                }
                #endregion

                #region Harass
                HarassMenu = Menu.AddSubMenu("Harass", "UBAddons.HarassMenu" + player.Hero, "Settings your harass below");
                {
                    HarassMenu.CreatSlotCheckBox(SpellSlot.E);
                    HarassMenu.CreatManaLimit();
                    HarassMenu.CreatHarassKeyBind();
                }
                #endregion

                #region LaneClear
                LaneClearMenu = Menu.AddSubMenu("LaneClear", "UBAddons.LaneClear" + player.Hero, "Settings your laneclear below");
                {
                    LaneClearMenu.CreatLaneClearOpening();
                    LaneClearMenu.CreatSlotCheckBox(SpellSlot.W, null, false);
                    LaneClearMenu.CreatSlotHitSlider(SpellSlot.W, 5, 1, 10);
                    LaneClearMenu.CreatSlotCheckBox(SpellSlot.E, null, false);
                    LaneClearMenu.CreatSlotHitSlider(SpellSlot.E, 5, 1, 10);
                    LaneClearMenu.CreatManaLimit();
                }
                #endregion

                #region JungleClear
                JungleClearMenu = Menu.AddSubMenu("JungleClear", "UBAddons.JungleClear" + player.Hero, "Settings your jungleclear below");
                {
                    JungleClearMenu.CreatSlotCheckBox(SpellSlot.Q, null, false);
                    JungleClearMenu.CreatSlotCheckBox(SpellSlot.W, null, false);
                    JungleClearMenu.CreatSlotCheckBox(SpellSlot.E);
                    JungleClearMenu.CreatManaLimit();
                }
                #endregion

                #region LastHit
                LastHitMenu = Menu.AddSubMenu("Lasthit", "UBAddons.Lasthit" + player.Hero, "UB" + player.Hero + " - Settings your unkillable minion below");
                {
                    LastHitMenu.CreatLasthitOpening();
                    LastHitMenu.CreatSlotCheckBox(SpellSlot.E, null, false);
                    LastHitMenu.CreatManaLimit();
                }
                #endregion

                #region Misc
                MiscMenu = Menu.AddSubMenu("Misc", "UBAddons.Misc" + player.Hero, "Settings your misc below");
                {
                    MiscMenu.AddGroupLabel("Anti Gapcloser settings");
                    MiscMenu.CreatMiscGapCloser();
                    MiscMenu.CreatSlotCheckBox(SpellSlot.W, "GapCloser");
                }
                #endregion

                #region Drawings
                DrawMenu = Menu.AddSubMenu("Drawings", "UBAddons.Drawings" + player.Hero, "Settings your drawings below");
                {
                    DrawMenu.CreatDrawingOpening();
                    DrawMenu.Add("UBAddons.Twitch.Passive.Draw", new ComboBox("Draw Time Passive", 2, "Disable", "Circular", "Line", "Number"));
                    DrawMenu.Add("UBAddons.Twitch.Passive.ColorPicker", new ColorPicker("Dagger Color", ColorReader.Load("UBAddons.Twitch.Passive.ColorPicker", Color.GreenYellow)));
                    DrawMenu.CreatColorPicker(SpellSlot.W);
                    DrawMenu.CreatColorPicker(SpellSlot.E);
                    DrawMenu.CreatColorPicker(SpellSlot.R);
                    DrawMenu.CreatColorPicker(SpellSlot.Unknown);
                }
                #endregion

                DamageIndicator.Initalize(MenuValue.Drawings.ColorDmg);
            }
            catch (Exception exception)
            {
                Debug.Print(exception.ToString(), Console_Message.Error);
            }
        }
Exemple #8
0
        protected override void CreateMenu()
        {
            try
            {
                #region Mainmenu
                Menu = MainMenu.AddMenu("UB" + player.Hero, "UBAddons.MainMenu" + player.Hero, "UB" + player.Hero + " - UBAddons - by U.Boruto");
                Menu.AddGroupLabel("General Setting");
                Menu.CreatSlotHitChance(SpellSlot.E);
                Menu.CreatSlotHitChance(SpellSlot.R);
                #endregion

                #region Combo
                ComboMenu = Menu.AddSubMenu("Combo", "UBAddons.ComboMenu" + player.Hero, "UB" + player.Hero + " - Settings your combo below");
                {
                    ComboMenu.CreatSlotCheckBox(SpellSlot.Q);
                    ComboMenu.CreatSlotCheckBox(SpellSlot.W);
                    ComboMenu.CreatSlotComboBox(SpellSlot.W, 1, "Safe", "Damage");
                    ComboMenu.CreatSlotCheckBox(SpellSlot.E);
                    ComboMenu.CreatSlotCheckBox(SpellSlot.R);
                    ComboMenu.AddGroupLabel("E Setting");
                    ComboMenu.Add("UBAddons.Katarina.E.Turret.Disabble", new CheckBox("Prevent E to turret"));
                    ComboMenu.Add("UBAddons.Katarina.E.Killable.Only", new CheckBox("Only E if killable"));
                    ComboMenu.Add("UBAddons.Katarina.E.Killable.Anyway", new CheckBox("E anyway if killable"));
                    ComboMenu.Add("UBAddons.Katarina.E.To.Minion", new CheckBox("E To Minion", false));
                    ComboMenu.Add("UBAddons.Katarina.E.To.Champ.Enemy", new CheckBox("E To Enemy Champ"));
                    ComboMenu.Add("UBAddons.Katarina.E.To.Champ.Ally", new CheckBox("E To Ally Champ"));
                    ComboMenu.Add("UBAddons.Katarina.E.To.Dagger", new CheckBox("E To Dagger"));
                    ComboMenu.Add("UBAddons.Katarina.E.Kill", new ComboBox("When one enemy killed, I want E to", 0, "Smart", "Unit near Cursor", "Next Target"));
                }
                #endregion

                #region Harass
                HarassMenu = Menu.AddSubMenu("Harass", "UBAddons.HarassMenu" + player.Hero, "UB" + player.Hero + " - Settings your harass below");
                {
                    HarassMenu.CreatSlotCheckBox(SpellSlot.Q);
                    HarassMenu.CreatSlotCheckBox(SpellSlot.W);
                    HarassMenu.CreatSlotCheckBox(SpellSlot.E);
                    HarassMenu.CreatHarassKeyBind();
                }
                #endregion

                #region LaneClear
                LaneClearMenu = Menu.AddSubMenu("LaneClear", "UBAddons.LaneClear" + player.Hero, "UB" + player.Hero + " - Settings your laneclear below");
                {
                    LaneClearMenu.CreatLaneClearOpening();
                    LaneClearMenu.CreatSlotCheckBox(SpellSlot.Q, null, false);
                    LaneClearMenu.CreatSlotCheckBox(SpellSlot.W, null, false);
                    LaneClearMenu.CreatSlotHitSlider(SpellSlot.W, 5, 1, 10);
                    LaneClearMenu.CreatSlotCheckBox(SpellSlot.E, null, false);
                    LaneClearMenu.CreatSlotHitSlider(SpellSlot.E, 5, 1, 10);
                }
                #endregion

                #region JungleClear
                JungleClearMenu = Menu.AddSubMenu("JungleClear", "UBAddons.JungleClear" + player.Hero, "UB" + player.Hero + " - Settings your jungleclear below");
                {
                    JungleClearMenu.CreatSlotCheckBox(SpellSlot.Q, null, false);
                    JungleClearMenu.CreatSlotCheckBox(SpellSlot.W);
                    JungleClearMenu.CreatSlotCheckBox(SpellSlot.E, null, false);
                }
                #endregion

                #region Lasthit
                LasthitMenu = Menu.AddSubMenu("Lasthit", "UBAddons.Lasthit" + player.Hero, "UB" + player.Hero + " - Settings your unkillable minion below");
                {
                    LasthitMenu.CreatLasthitOpening();
                    LasthitMenu.CreatSlotCheckBox(SpellSlot.Q);
                    LasthitMenu.CreatSlotCheckBox(SpellSlot.E, null, false);
                }
                #endregion

                #region Flee
                FleeMenu = Menu.AddSubMenu("Flee", "UBAddons.Flee" + player.Hero, "Setting your flee below");
                {
                    string BeginText = Variables.AddonName + "." + Player.Instance.Hero + ".";
                    FleeMenu.Add(BeginText + "E", new CheckBox("Use E for flee"));
                    FleeMenu.Add(BeginText + "E.ToDagger", new CheckBox("E to dagger"));
                    FleeMenu.Add(BeginText + "E.ToMinion", new CheckBox("E to minion"));
                    FleeMenu.Add(BeginText + "E.ToMonster", new CheckBox("E to monster"));
                    FleeMenu.Add(BeginText + "E.ToChamp", new CheckBox("E to champ"));
                    FleeMenu.Add(BeginText + "E.HP", new Slider("Min {0}% HP for E champ & monster", 15));
                }
                #endregion

                #region Misc
                MiscMenu = Menu.AddSubMenu("Misc", "UBAddons.Misc" + player.Hero, "UB" + player.Hero + " - Settings your misc below");
                {
                    MiscMenu.AddGroupLabel("Anti Gapcloser settings");
                    MiscMenu.CreatMiscGapCloser();
                    MiscMenu.CreatSlotCheckBox(SpellSlot.W, "GapCloser");
                    MiscMenu.AddGroupLabel("Interrupter settings");
                    MiscMenu.AddGroupLabel("Killsteal settings");
                    MiscMenu.CreatSlotCheckBox(SpellSlot.Q, "KillSteal");
                    MiscMenu.CreatSlotCheckBox(SpellSlot.E, "KillSteal");
                    MiscMenu.CreatSlotCheckBox(SpellSlot.R, "KillSteal");
                }
                #endregion

                #region Drawings
                DrawMenu = Menu.AddSubMenu("Drawings");
                {
                    DrawMenu.CreatDrawingOpening();
                    DrawMenu.Add("UBAddons.Katarina.Dagger.Draw", new ComboBox("Draw Time", 0, "Disable", "Circular", "Line", "Number"));
                    DrawMenu.Add("UBAddons.Katarina.Draw.Status", new CheckBox("Draw status"));
                    DrawMenu.Add("UBAddons.Katarina.Dagger.ColorPicker", new ColorPicker("Dagger Color", ColorReader.Load("UBAddons.Katarina.Dagger.ColorPicker", Color.GreenYellow)));
                    DrawMenu.CreatColorPicker(SpellSlot.Q);
                    DrawMenu.CreatColorPicker(SpellSlot.E);
                    DrawMenu.CreatColorPicker(SpellSlot.R);
                    DrawMenu.CreatColorPicker(SpellSlot.Unknown);
                }
                #endregion

                DamageIndicator.Initalize(MenuValue.Drawings.ColorDmg);
            }
            catch (Exception exception)
            {
                Debug.Print(exception.ToString(), Console_Message.Error);
            }
        }