From e2e249654c87a6ee2814e35a3e987f84023bf6fd Mon Sep 17 00:00:00 2001 From: Kade M Date: Sun, 20 Dec 2020 15:25:44 -0800 Subject: [PATCH] Update 1.1 --- FNFBot.sln | 16 ++ FNFBot/FNFBot.csproj | 69 +++++++++ FNFBot/KeyboardHook.cs | 75 ++++++++++ FNFBot/Program.cs | 240 ++++++++++++++++++++++++++++++ FNFBot/Properties/AssemblyInfo.cs | 35 +++++ FNFBot/packages.config | 5 + 6 files changed, 440 insertions(+) create mode 100644 FNFBot.sln create mode 100644 FNFBot/FNFBot.csproj create mode 100644 FNFBot/KeyboardHook.cs create mode 100644 FNFBot/Program.cs create mode 100644 FNFBot/Properties/AssemblyInfo.cs create mode 100644 FNFBot/packages.config diff --git a/FNFBot.sln b/FNFBot.sln new file mode 100644 index 0000000..b70c162 --- /dev/null +++ b/FNFBot.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNFBot", "FNFBot\FNFBot.csproj", "{7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/FNFBot/FNFBot.csproj b/FNFBot/FNFBot.csproj new file mode 100644 index 0000000..2e51b64 --- /dev/null +++ b/FNFBot/FNFBot.csproj @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + {7A9C6B6A-07AA-4E23-BD8F-A8CB29810205} + Exe + Properties + FNFBot + FNFBot + v4.7.2 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\FNFDataAPI\FNFDataAPI\bin\Debug\FNFDataAPI.dll + + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + True + + + + + + + + ..\packages\InputSimulator.1.0.4.0\lib\net20\WindowsInput.dll + True + + + + + + + + + + + + + + diff --git a/FNFBot/KeyboardHook.cs b/FNFBot/KeyboardHook.cs new file mode 100644 index 0000000..484da4c --- /dev/null +++ b/FNFBot/KeyboardHook.cs @@ -0,0 +1,75 @@ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +// +// Not created by KadeDev, all rights go to rqnn (https://stackoverflow.com/a/46014022) +// + + +public class LowLevelKeyboardHook +{ + private const int WH_KEYBOARD_LL = 13; + private const int WM_KEYDOWN = 0x0100; + private const int WM_SYSKEYDOWN = 0x0104; + private const int WM_KEYUP = 0x101; + private const int WM_SYSKEYUP = 0x105; + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool UnhookWindowsHookEx(IntPtr hhk); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); + + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + private static extern IntPtr GetModuleHandle(string lpModuleName); + + public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); + + public event EventHandler OnKeyPressed; + public event EventHandler OnKeyUnpressed; + + private LowLevelKeyboardProc _proc; + private IntPtr _hookID = IntPtr.Zero; + + public LowLevelKeyboardHook() + { + _proc = HookCallback; + } + + public void HookKeyboard() + { + _hookID = SetHook(_proc); + } + + public void UnHookKeyboard() + { + UnhookWindowsHookEx(_hookID); + } + + private IntPtr SetHook(LowLevelKeyboardProc proc) + { + using (Process curProcess = Process.GetCurrentProcess()) + using (ProcessModule curModule = curProcess.MainModule) + { + return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); + } + } + + private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) + { + if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN) + { + int vkCode = Marshal.ReadInt32(lParam); + + OnKeyPressed.Invoke(this, ((Keys)vkCode)); + } + + return CallNextHookEx(_hookID, nCode, wParam, lParam); + } +} \ No newline at end of file diff --git a/FNFBot/Program.cs b/FNFBot/Program.cs new file mode 100644 index 0000000..1549c20 --- /dev/null +++ b/FNFBot/Program.cs @@ -0,0 +1,240 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Threading; +using System.Windows.Forms; +using WindowsInput; +using WindowsInput.Native; +using FridayNightFunkin; + +namespace FNFBot +{ + internal class Program + { + public static int offset = 25; + + [STAThread] + 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 notesToPlay = new List(); + if (sect.Notes.Count == 0) + continue; + + if (sect.MustHitSection) + { + foreach (FNFSong.FNFNote n in sect.Notes) + 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(); + } + + [DllImport("user32.dll", SetLastError = true)] + static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo); + + public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag + public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag + + public static void KeyPress(byte key, byte scan) + { + keybd_event(key, scan, KEYEVENTF_EXTENDEDKEY, 0); + Thread.Sleep(offset); + keybd_event(key, scan, KEYEVENTF_KEYUP, 0); + } + } +} \ No newline at end of file diff --git a/FNFBot/Properties/AssemblyInfo.cs b/FNFBot/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7b793b5 --- /dev/null +++ b/FNFBot/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FNFCheat")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FNFCheat")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7A9C6B6A-07AA-4E23-BD8F-A8CB29810205")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/FNFBot/packages.config b/FNFBot/packages.config new file mode 100644 index 0000000..754d2bc --- /dev/null +++ b/FNFBot/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file