Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        private static void DoWork()
        {
            if (mhw != null && !ct.IsCancellationRequested)
            {
                InputSimulator sim = new InputSimulator();
                SaveData       sd  = new SaveData(mhw, ct);

                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 && !ct.IsCancellationRequested)
                {
                    Logger.LogInfo($"Gauge Data {sd.SteamGauge}!");

                    // value of the offset address
                    var ordered = ExtractCorrectSequence(mhw, offset_Address);
                    if (ordered == null)
                    {
                        Logger.LogInfo("The Steamworks minigame is not started. Please enter the minigame and Press 'Space' so that you see the first letters on your screen.");

                        // try again..
                        continue;
                    }

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

                            var item = ordered[index];

                            byte after = before;
                            while (before == after && !ct.IsCancellationRequested)
                            {
                                while (!IsCurrnetActiveMHW())
                                {
                                    Logger.LogInfo("MHW not active.");
                                }
                                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 && !ct.IsCancellationRequested)
                    {
                        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();
            }
        }