示例#1
0
        private static void DoRandomWork()
        {
            if (mhw != null && !ct.IsCancellationRequested)
            {
                InputSimulator sim = new InputSimulator();
                while (!shouldStop && !ct.IsCancellationRequested)
                {
                    List <int> orderBytes = rndPatterns[rnd.Next(0, 5)];

                    if (Settings.IsAzerty)
                    {
                        keyOrder[VirtualKeyCode.VK_Q] = orderBytes[0];   // Q
                        keyOrder[VirtualKeyCode.VK_Z] = orderBytes[1];   // Z
                        keyOrder[VirtualKeyCode.VK_D] = orderBytes[2];   // D
                    }
                    else
                    {
                        keyOrder[VirtualKeyCode.VK_A] = orderBytes[0];   // A
                        keyOrder[VirtualKeyCode.VK_W] = orderBytes[1];   // W
                        keyOrder[VirtualKeyCode.VK_D] = orderBytes[2];   // D
                    }

                    foreach (var item in keyOrder.OrderBy(x => x.Value).Take(3).ToList())
                    {
                        PressKey(sim, item.Key, true);
                    }
                }

                api.Dispose();
            }
        }
 public static void Unhook()
 {
     if (keystroke != null)
     {
         keystroke.Dispose();
         keystroke = null;
     }
 }
示例#3
0
        private static void DoRandomWork()
        {
            if (mhw != null && !ct.IsCancellationRequested)
            {
                InputSimulator sim = new InputSimulator();
                while (!shouldStop && !ct.IsCancellationRequested)
                {
                    List <KeyValuePair <VirtualKeyCode, int> > orderBytes = GetRandomSequence();

                    foreach (var item in orderBytes)
                    {
                        PressKey(sim, item.Key, true);
                    }

                    PressKey(sim, (VirtualKeyCode)Settings.KeyCutsceneSkip, true);

                    PressKey(sim, VirtualKeyCode.SPACE, true);
                }

                api.Dispose();
            }
        }
示例#4
0
        private void PrepWindow_OnExitEvent(object source, EventArgs args)
        {
            Dispatch(() =>
            {
                cts.Cancel();

                api.Dispose();

                UnHookEvents();

                this.Close();
            });
        }
示例#5
0
文件: Form1.cs 项目: xkre/KeyLogger
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     _keystrokeApi.Dispose();
     _sw.Close();
 }
示例#6
0
        private static void DoWork()
        {
            HookKeyboardEvents();

            Process mhw = GetMHW();

            while (!shouldStart || mhw == null)
            {
                Thread.Sleep(1000);
                mhw = GetMHW();

                //MainWindowTitle = "MONSTER HUNTER: WORLD(404549)"
                if (!mhw.MainWindowTitle.Contains(Settings.SupportedGameVersion))
                {
                    var currentVersion = int.Parse(mhw.MainWindowTitle.Split('(')[1].Replace(")", ""));
                    Logger.LogError($"Currently built for version: {Settings.SupportedGameVersion}. This game version ({currentVersion}) is not supported YET!");

                    mhw = null;
                }
            }

            if (mhw != null)
            {
                InputSimulator sim = new InputSimulator();
                SaveData       sd  = new SaveData(mhw);

                ulong starter = Settings.Off_Base + Settings.Off_SteamworksCombo;

                var pointerAddress = MemoryHelper.Read <ulong>(mhw, starter);
                // offset the address
                var offset_Address          = pointerAddress + 0x350;
                var offset_buttonPressState = offset_Address + 8;

                while (!shouldStop)
                {
                    Logger.LogInfo($"Gauge Data {sd.SteamGauge}!");

                    // value of the offset address
                    var ordered = ExtractCorrectSequence(mhw, offset_Address);
                    if (ordered == null)
                    {
                        // try again..
                        continue;
                    }

                    int index = 0;
                    while (index < 3)
                    {
                        try
                        {
                            var before = MemoryHelper.Read <byte>(mhw, offset_buttonPressState);

                            var item = ordered[index];

                            //PressKey(sim, item.Key);

                            byte after = before;
                            while (before == after)
                            {
                                PressKey(sim, item.Key);

                                after = MemoryHelper.Read <byte>(mhw, offset_buttonPressState);
                            }

                            index++;
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError($"Trying to press button sequence: {ex.Message}");
                        }
                    }

                    if (shouldStop)
                    {
                        break;
                    }

                    var currentState = MemoryHelper.Read <byte>(mhw, offset_buttonPressState);
                    while (currentState != (int)ButtonPressingState.BeginningOfSequence)
                    {
                        Thread.Sleep(50);

                        try
                        {
                            PressKey(sim, (VirtualKeyCode)Settings.KeyCutsceneSkip);

                            // no more fuel
                            if (currentState == (int)ButtonPressingState.EndOfGame)
                            {
                                if (sd.NaturalFuel + sd.StoredFuel < 10)
                                {
                                    Logger.LogInfo("No more fuel, stopping bot.");
                                    shouldStop = true;
                                    break;
                                }

                                if (sd.SteamGauge == 0)
                                {
                                    PressKey(sim, VirtualKeyCode.SPACE);
                                }
                            }

                            if (shouldStop)
                            {
                                break;
                            }

                            currentState = MemoryHelper.Read <byte>(mhw, offset_buttonPressState);
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError($"Trying to finish up combo: {ex.Message}");
                        }
                    }
                }

                api.Dispose();
            }
        }