示例#1
0
        private static async Task ExecuteTasks(UsersInfo curUser, QuestionPrediction uTask, SocketUserMessage messageParam, SocketCommandContext context)
        {
            var requestInfo = new AgentRequestInfo
            {
                User          = curUser,
                SocketMessage = messageParam,
                Context       = context
            };

            #region Lock process, auto detect process
            if (uTask.TypeEnum() == EQuestionType.LockProcess ||
                uTask.TypeEnum() == EQuestionType.Find && uTask.TaskEnum() == EQuestionTask.Process ||
                uTask.TypeEnum() == EQuestionType.Set && uTask.TaskEnum() == EQuestionTask.Process)
            {
                // Try to get process id
                bool findProcessId = !context.Message.Content.Contains("0x")
                    ? int.TryParse(Regex.Match(context.Message.Content, @"\d+").Value, out int processId)
                    : int.TryParse(context.Message.Content.Split("0x")[1], NumberStyles.HexNumber, new NumberFormatInfo(), out processId);

                // Try auto detect it
                if (!findProcessId)
                {
                    processId = Utils.DetectUnrealGame();
                }

                // not valid process
                if (processId == 0 || !Memory.Memory.IsValidProcess(processId))
                {
                    await context.User.SendMessageAsync($"I can't found your `target`. " +
                                                        (!findProcessId ? "\nI tried to `detect any running target`, but i can't `see anyone`. !! " : null) +
                                                        DiscordText.GetRandomSadEmoji());

                    return;
                }

                // Setup Memory
                Utils.MemObj  = new Memory.Memory(processId);
                Utils.ScanObj = new Scanner(Utils.MemObj);

                Utils.MemObj.SuspendProcess();

                // Get Game Unreal Version
                if (!Utils.UnrealEngineVersion(out string ueVersion) || string.IsNullOrWhiteSpace(ueVersion))
                {
                    ueVersion = "Can Not Detected";
                }

                // Load Engine File
                // TODO: Make engine name dynamically stetted by user
                string corePath  = Path.Combine(ConfigPath, "EngineCore");
                var    coreNames = Directory.EnumerateFiles(corePath).Select(Path.GetFileName).ToList();

                string ueVersionO = ueVersion;
                ueVersion = await Utils.DiscordManager.OptionsQuestion(
                    requestInfo,
                    $"Select EngineCore file to use.{Utils.NLine}(Detected For Your Target Is `{ueVersion}`)",
                    coreNames);

                JsonReflector.LoadJsonEngine(ueVersion);

                var emb = new EmbedBuilder
                {
                    Color       = Color.Green,
                    Title       = "Target Info",
                    Description = "**Information** about your __target__.",
                };
                emb.WithUrl(Utils.DonateUrl);
                emb.WithFooter(Utils.DiscordFooterText, Utils.DiscordFooterImg);

                emb.AddField("Process ID", $"0x{Utils.MemObj.TargetProcess.Id:X} | {Utils.MemObj.TargetProcess.Id}");
                emb.AddField("Game Architecture", Utils.MemObj.Is64Bit ? "64Bit" : "32bit");
                emb.AddField("Window Name", Utils.MemObj.TargetProcess.MainWindowTitle);
                emb.AddField("Exe Name", Path.GetFileName(Utils.MemObj.TargetProcess.MainModule?.FileName));
                emb.AddField("Modules Count", Utils.MemObj.TargetProcess.Modules.Count);
                emb.AddField("Unreal Version", ueVersionO);

                await context.User.SendMessageAsync(embed : emb.Build());
            }
            #endregion

            #region Finder
            else if (uTask.TypeEnum() == EQuestionType.Find)
            {
                if (Utils.MemObj == null)
                {
                    if (uTask.TaskEnum() == EQuestionTask.None)
                    {
                        await context.User.SendMessageAsync(DiscordText.GetRandomNotUnderstandString());
                    }
                    else
                    {
                        await context.User.SendMessageAsync($"Give me your target FIRST !!");
                    }
                    curUser.LastOrder = UserOrder.GetProcess;
                    return;
                }

                if (uTask.TaskEnum() == EQuestionTask.None)
                {
                    await context.User.SendMessageAsync(DiscordText.GetRandomNotUnderstandString());

                    return;
                }

                var lastMessage = await context.User.SendMessageAsync($":white_check_mark: Working on that.");

                // Do work
                var finderResult = new List <IntPtr>();
                switch (uTask.TaskEnum())
                {
                case EQuestionTask.GNames:
                    finderResult = await GNamesFinder.Find(requestInfo);

                    break;

                case EQuestionTask.GObject:
                    finderResult = await GObjectsFinder.Find(requestInfo);

                    break;
                }

                if (finderResult.Empty())
                {
                    await lastMessage.ModifyAsync(msg => msg.Content = ":x: Can't found any thing !!");

                    return;
                }

                var emb = new EmbedBuilder
                {
                    Color       = Color.Green,
                    Title       = $"Finder Result ({uTask.TaskEnum():G})",
                    Description = "That's what i found for you :-\n\n",
                };
                emb.WithUrl(Utils.DonateUrl);
                emb.WithFooter(Utils.DiscordFooterText, Utils.DiscordFooterImg);

                bool isGnames = uTask.TaskEnum() == EQuestionTask.GNames;
                for (int i = 0; i < finderResult.Count; i++)
                {
                    string validStr = (isGnames ? Utils.IsValidGNamesAddress(finderResult[i]) : Utils.IsTUobjectArray(finderResult[i])) ? "Valid" : "Not Valid";
                    emb.Description += $"{DiscordText.GetEmojiNumber(i + 1, true)}) `0x{finderResult[i].ToInt64():X}` ({validStr}).{Utils.NLine}";
                }

                await lastMessage.ModifyAsync(msg =>
                {
                    msg.Content = string.Empty;
                    msg.Embed   = emb.Build();
                });

                await lastMessage.AddReactionsAsync(DiscordText.GenEmojiNumberList(finderResult.Count, false));
            }
            #endregion

            #region Sdk Generator
            else if (uTask.TypeEnum() == EQuestionType.SdkDump)
            {
                if (Utils.MemObj == null)
                {
                    await context.User.SendMessageAsync($"Give me your target FIRST !!");

                    curUser.LastOrder = UserOrder.GetProcess;
                    return;
                }

                var dumpState = await new SdkGenerator(curUser.GobjectsPtr, curUser.GnamesPtr).Start(requestInfo);
                if (dumpState.State == SdkGenerator.GeneratorState.Good)
                {
                    await context.Channel.SendMessageAsync($"__Take__ => {DateTime.Now - dumpState.StartTime:t}");
                }
                else
                {
                    await context.Channel.SendMessageAsync($"__Problem__ => {dumpState.State:G}");
                }
            }
            #endregion

            #region Open
            else if (uTask.TypeEnum() == EQuestionType.Open)
            {
                if (uTask.TaskEnum() == EQuestionTask.Sdk)
                {
                    Utils.OpenFolder(GenPath);
                }
                else if (uTask.TaskEnum() == EQuestionTask.Tool)
                {
                    Utils.OpenFolder(Environment.CurrentDirectory);
                }
            }
            #endregion

            #region Help
            else if (uTask.TypeEnum() == EQuestionType.Help)
            {
                var emb = new EmbedBuilder();
                emb.WithUrl(Utils.DonateUrl);
                emb.WithFooter(Utils.DiscordFooterText, Utils.DiscordFooterImg);

                emb.Title       = "How To Use";
                emb.Description = File.ReadAllText(Path.Combine(ConfigPath, "help.txt"));

                await context.Channel.SendMessageAsync(embed : emb.Build());
            }
            #endregion

            #region Set
            else if (uTask.TypeEnum() == EQuestionType.Set)
            {
                if (Utils.MemObj == null)
                {
                    if (uTask.TaskEnum() == EQuestionTask.None)
                    {
                        await context.User.SendMessageAsync(DiscordText.GetRandomNotUnderstandString());
                    }
                    else
                    {
                        await context.User.SendMessageAsync($"Give me your target FIRST !!");
                    }
                    curUser.LastOrder = UserOrder.GetProcess;
                    return;
                }

                bool foundAddress;
                long address;

                if (context.Message.Content.Contains("0x"))
                {
                    foundAddress = long.TryParse(context.Message.Content.Split("0x")[1],
                                                 NumberStyles.HexNumber, new NumberFormatInfo(), out address);
                }
                else
                {
                    foundAddress = false;
                    address      = 0x0;
                }

                if (!foundAddress)
                {
                    await context.Channel.SendMessageAsync($"**What to set** !!, __I can't see any thing__.!");

                    return;
                }

                if (uTask.TaskEnum() == EQuestionTask.GNames)
                {
                    if (Utils.IsValidGNamesAddress((IntPtr)address))
                    {
                        curUser.GnamesPtr = (IntPtr)address;
                    }
                    else
                    {
                        await context.Channel.SendMessageAsync($"**Looks wrong address** !!, `Remember i need a static address`.");
                    }
                }
                else if (uTask.TaskEnum() == EQuestionTask.GObject)
                {
                    if (Utils.IsTUobjectArray((IntPtr)address))
                    {
                        curUser.GobjectsPtr = (IntPtr)address;
                    }
                    else
                    {
                        await context.Channel.SendMessageAsync($"**Looks wrong address** !!, `Remember i need a static address`.");
                    }
                }
            }
            #endregion
        }