Пример #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            LowLevelKeyboardHook kbh = new LowLevelKeyboardHook();

            kbh.OnKeyPressed   += kbh_OnKeyPressed;
            kbh.OnKeyUnpressed += kbh_OnKeyUnpressed;
            kbh.HookKeyboard();

            Application.Run();

            kbh.UnHookKeyboard();
        }
Пример #2
0
 private void setup()
 {
     STARTING_HEIGHT     = Size.Height;
     ACTUAL_MINIMUM_SIZE = MinimumSize;
     characters_view     = Storage.characters.AsDataView();
     update_filter();
     characters_view.Sort            = "roll DESC, mod DESC, name ASC";
     characters_view.ListChanged    += update_list;
     Storage.active_ids.ListChanged += update_filter;
     keyboard_hook = new LowLevelKeyboardHook();
     keyboard_hook.OnKeyPressed   += global_key_pressed;
     keyboard_hook.OnKeyUnpressed += global_key_unpressed;
     keyboard_hook.HookKeyboard();
     load_cosmetics();
     update_growth_direction();
     Storage.settings.PropertyChanged += handle_settings_changed;
 }
Пример #3
0
        public static void Main(string[] args)
        {
            Console.Title = "Init";
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Console.WriteLine("Directory: ");
            string         dir          = Console.ReadLine();
            InputSimulator simulator    = new InputSimulator();
            FNFSong        song         = null;
            bool           playing      = false;
            Stopwatch      watch        = new Stopwatch();
            int            section      = 0;
            bool           waitingStart = false;

            Console.WriteLine("hooking keyboard shit");

            LowLevelKeyboardHook kbh = new LowLevelKeyboardHook();

            kbh.OnKeyPressed += (sender, keys) =>
            {
                switch (keys)
                {
                case Keys.F1:
                    watch.Reset();
                    watch.Start();
                    playing = true;
                    Console.WriteLine("Started playing...");
                    break;

                case Keys.F2:
                    playing = false;
                    Console.WriteLine("Stopped playing...");
                    waitingStart = false;
                    break;

                case Keys.F3:
                    Console.WriteLine("offset: " + offset);
                    offset++;
                    break;

                case Keys.F4:
                    Console.WriteLine("offset: " + offset);
                    offset--;
                    break;

                case Keys.F5:
                    playing = false;
                    Console.WriteLine("Restarting...");
                    break;
                }
            };
            kbh.HookKeyboard();

            Console.WriteLine("hooked :>");
            int notesPlayed = 0;

            new Thread(() =>
            {
                while (true)
                {
                    Console.Title = "FNFBot 1.1";
                    if (playing)
                    {
                        foreach (FNFSong.FNFSection sect in song.Sections)
                        {
                            List <FNFSong.FNFNote> notesToPlay = new List <FNFSong.FNFNote>();
                            if (sect.Notes.Count == 0)
                            {
                                continue;
                            }

                            if (sect.MustHitSection)
                            {
                                foreach (FNFSong.FNFNote n in sect.Notes)
                                {
                                    if ((int)n.Type >= 4)
                                    {
                                        continue;
                                    }
                                    notesToPlay.Add(n);
                                }
                            }
                            else
                            {
                                foreach (FNFSong.FNFNote n in sect.Notes)
                                {
                                    if ((decimal)n.Type >= 4)
                                    {
                                        notesToPlay.Add(n);
                                    }
                                }
                            }

                            notesPlayed = 0;

                            foreach (FNFSong.FNFNote not in notesToPlay)
                            {
                                new Thread(() =>
                                {
                                    bool shouldHold = not.Length > 0;

                                    if (!playing)
                                    {
                                        Thread.CurrentThread.Abort();
                                    }

                                    Console.WriteLine("Queing " + not.Type + " at " + not.Time);

                                    while ((decimal)watch.Elapsed.TotalMilliseconds < not.Time)
                                    {
                                        Thread.Sleep(1);
                                        if (!playing)
                                        {
                                            Thread.CurrentThread.Abort();
                                        }
                                    }

                                    if (!playing)
                                    {
                                        Thread.CurrentThread.Abort();
                                    }

                                    switch (not.Type)
                                    {
                                    case FNFSong.NoteType.Left:
                                    case FNFSong.NoteType.RLeft:
                                        if (shouldHold)
                                        {
                                            simulator.Keyboard.KeyDown(VirtualKeyCode.LEFT);
                                            Thread.Sleep(Convert.ToInt32(not.Length));
                                            simulator.Keyboard.KeyUp(VirtualKeyCode.LEFT);
                                        }
                                        else
                                        {
                                            KeyPress(0x41, 0x1e);
                                        }

                                        break;

                                    case FNFSong.NoteType.Down:
                                    case FNFSong.NoteType.RDown:
                                        if (shouldHold)
                                        {
                                            simulator.Keyboard.KeyDown(VirtualKeyCode.DOWN);
                                            Thread.Sleep(Convert.ToInt32(not.Length));
                                            simulator.Keyboard.KeyUp(VirtualKeyCode.DOWN);
                                        }
                                        else
                                        {
                                            KeyPress(0x53, 0x1f);
                                        }

                                        break;

                                    case FNFSong.NoteType.Up:
                                    case FNFSong.NoteType.RUp:
                                        if (shouldHold)
                                        {
                                            simulator.Keyboard.KeyDown(VirtualKeyCode.UP);
                                            Thread.Sleep(Convert.ToInt32(not.Length));
                                            simulator.Keyboard.KeyUp(VirtualKeyCode.UP);
                                        }
                                        else
                                        {
                                            KeyPress(0x57, 0x11);
                                        }


                                        break;

                                    case FNFSong.NoteType.Right:
                                    case FNFSong.NoteType.RRight:
                                        if (shouldHold)
                                        {
                                            simulator.Keyboard.KeyDown(VirtualKeyCode.RIGHT);
                                            Thread.Sleep(Convert.ToInt32(not.Length));
                                            simulator.Keyboard.KeyUp(VirtualKeyCode.RIGHT);
                                        }
                                        else
                                        {
                                            KeyPress(0x44, 0x20);
                                        }

                                        break;
                                    }

                                    notesPlayed++;
                                }).Start();
                            }

                            while (notesPlayed != notesToPlay.Count)
                            {
                                Thread.Sleep(1);
                                if (!playing)
                                {
                                    break;
                                }
                            }

                            Console.WriteLine("Going to next section...");
                        }

                        playing      = false;
                        waitingStart = false;
                        Console.WriteLine("Song completed!");
                    }
                    else if (!waitingStart)
                    {
                        watch.Restart();
                        watch.Stop();
                        try
                        {
                            Console.WriteLine("Song Name: ");
                            string name = Console.ReadLine();
                            Console.WriteLine("Diff (none = normal): ");
                            string diff = Console.ReadLine();
                            Console.WriteLine("Trying to load " +
                                              $@"{dir}\assets\data\{name}\{name}{(diff != "" ? "-" + diff : "")}.json");

                            song = new FNFSong(
                                $@"{dir}\assets\data\{name}\{name}{(diff != "" ? "-" + diff : "")}.json");

                            Console.WriteLine("Loaded " + song.SongName + " with " + song.Sections.Count + " sections.");

                            Console.WriteLine("Press F1 to start");
                            waitingStart = true;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Failed to load that song. Exception: " + e);
                        }
                    }
                }
            }).Start();
            Application.Run();
            kbh.UnHookKeyboard();
        }
Пример #4
0
 public void start()
 {
     keyboardHook.HookKeyboard();
     streamer.start();
 }
Пример #5
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Console.WriteLine("Directory: ");
            string         dir       = Console.ReadLine();
            InputSimulator simulator = new InputSimulator();

            Song.Root song         = null;
            bool      playing      = false;
            Stopwatch watch        = new Stopwatch();
            int       section      = 0;
            bool      waitingStart = false;

            Console.WriteLine("hooking keyboard shit");

            LowLevelKeyboardHook kbh = new LowLevelKeyboardHook();

            kbh.OnKeyPressed += (sender, keys) =>
            {
                switch (keys)
                {
                case Keys.F1:
                    watch.Start();
                    playing = true;
                    Console.WriteLine("Started playing...");
                    break;

                case Keys.F2:
                    playing = false;
                    Console.WriteLine("Stopped playing...");
                    waitingStart = false;
                    break;

                case Keys.F3:
                    Console.WriteLine("offset: " + offset);
                    offset++;
                    break;

                case Keys.F4:
                    Console.WriteLine("offset: " + offset);
                    offset--;
                    break;
                }
            };
            kbh.HookKeyboard();

            List <PreAnalize.NoteHit> hit = null;

            Console.WriteLine("hooked :>");

            new Thread(() =>
            {
                while (true)
                {
                    if (playing)
                    {
                        foreach (PreAnalize.NoteHit h in hit)
                        {
                            bool shouldHold = h.length > 0;
                            while (watch.ElapsedMilliseconds < h.time)
                            {
                                if (!playing)
                                {
                                    break;
                                }
                            }
                            if (!playing)
                            {
                                break;
                            }
                            switch (h.type)
                            {
                            case 0:
                                if (shouldHold)
                                {
                                    simulator.Keyboard.KeyDown(VirtualKeyCode.LEFT);
                                    Thread.Sleep(Convert.ToInt32(h.length));
                                    simulator.Keyboard.KeyUp(VirtualKeyCode.LEFT);
                                }
                                else
                                {
                                    KeyPress(VirtualKeyCode.LEFT, simulator);
                                }
                                break;

                            case 1:
                                if (shouldHold)
                                {
                                    simulator.Keyboard.KeyDown(VirtualKeyCode.DOWN);
                                    Thread.Sleep(Convert.ToInt32(h.length));
                                    simulator.Keyboard.KeyUp(VirtualKeyCode.DOWN);
                                }
                                else
                                {
                                    KeyPress(VirtualKeyCode.DOWN, simulator);
                                }

                                break;

                            case 2:
                                if (shouldHold)
                                {
                                    simulator.Keyboard.KeyDown(VirtualKeyCode.UP);
                                    Thread.Sleep(Convert.ToInt32(h.length));
                                    simulator.Keyboard.KeyUp(VirtualKeyCode.UP);
                                }
                                else
                                {
                                    KeyPress(VirtualKeyCode.UP, simulator);
                                }


                                break;

                            case 3:
                                if (shouldHold)
                                {
                                    simulator.Keyboard.KeyDown(VirtualKeyCode.RIGHT);
                                    Thread.Sleep(Convert.ToInt32(h.length));
                                    simulator.Keyboard.KeyUp(VirtualKeyCode.RIGHT);
                                }
                                else
                                {
                                    KeyPress(VirtualKeyCode.RIGHT, simulator);
                                }

                                break;
                            }
                        }
                        playing = false;
                        Console.WriteLine("Song completed!");
                    }
                    else if (!waitingStart)
                    {
                        watch.Restart();
                        watch.Stop();
                        try
                        {
                            Console.WriteLine("Song Name: ");
                            string name = Console.ReadLine();
                            Console.WriteLine("Diff (none = normal): ");
                            string diff = Console.ReadLine();
                            Console.WriteLine("Trying to load " +
                                              $@"{dir}\assets\data\{name}\{name}{(diff != "" ? "-" + diff : "")}.json");

                            song = Song.LoadSong(
                                $@"{dir}\assets\data\{name}\{name}{(diff != "" ? "-" + diff : "")}.json");

                            hit = PreAnalize.Anal(song);

                            Console.WriteLine("Loaded " + song.song.SongSong + " with " + song.sections + " sections.");

                            Console.WriteLine("Press F1 to start");
                            waitingStart = true;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Failed to load that song. Exception: " + e);
                        }
                    }
                }
            }).Start();
            Application.Run();
            kbh.UnHookKeyboard();
        }