C++ 电子游戏机器人?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2741040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Video Game Bots?
提问by cam
Something I've always wondered, especially since it inspired me to start programming when I was a kid, was how video game bots work? I'm sure there are a lot of different methods, but what about automation for MMORPGs? Or even FPS-type bots?
我一直想知道的东西,尤其是当我还是个孩子的时候,它激励我开始编程,视频游戏机器人是如何工作的?我确信有很多不同的方法,但是 MMORPG 的自动化呢?甚至是 FPS 类型的机器人?
I'm talking about player-made automation bots.
我说的是玩家制作的自动化机器人。
回答by bta
To 'bot' a game, you need to be able to do two things programmatically: detect what's going on in the game, and provide input to the game.
要“机器人”游戏,您需要能够以编程方式做两件事:检测游戏中发生的事情,并为游戏提供输入。
Detecting what's going on in the game tends to be the harder of the two. A few methods for doing this are:
检测游戏中发生的事情往往是两者中较难的。执行此操作的几种方法是:
- Screen-ScrapingThis technique captures the image on the screen and parses it, looking for things like enemies, player status, power-ups, game messages, time clocks, etc. This tends to be a particularly difficult method. OCRtechniques can be used to process text, but if the text is written on top of the game world (instead of on a UI element with a solid background), the ever-changing backdrop can make it difficult to get accurate and consistent results. Finding non-text objects on the screen can be even more difficult, especially in 3D worlds, because of the many different positions and orientations that a single object may possibly exist in.
- Audio CuesIn some games, actions and events are accompanied by unique sound effects. It is possible to detect these events by monitoring the audio output of the game and matching it against a recording of the associated sound effect. Some games allow the player to provide their own sound effects for events, which allows the use of sound effects that are designed to be easy to listen for and filter out.
- Memory MonitoringIf the internal workings of the game are well understood, then you can monitor the state of a game by inspecting the game's memory space. Some cheat tools for console systems (such as the Game Genie) use this method. By detecting what memory the game updates, it is possible to detect what the game is doing. Some games randomize the memory locations they use each time they are launched in an attempt to foil this vulnerability.
- Packet AnalysisWith appropriate drivers, you can intercept the game's data packets as they are sent to or retrieved from your network card (for games played online). Analysisof these packets can reveal what your game client is communicating to the server, which usually revolves around player/enemy actions.
- Game ScriptingSome games have a built-in scripting interface. If available, this is usually the easiest method because it is something the game software is designed to do (the previous methods would all typically count as "hacks"). Some scripts must be run in-game (through a console or through an add-on system) and some can be run by external programs that communicate through the game via a published API.
- Screen-Scraping这种技术捕捉屏幕上的图像并对其进行解析,寻找诸如敌人、玩家状态、电源、游戏消息、时钟等内容。这往往是一种特别困难的方法。 OCR技术可用于处理文本,但如果文本写在游戏世界的顶部(而不是具有纯色背景的 UI 元素上),那么不断变化的背景会使获得准确和一致的结果变得困难。在屏幕上查找非文本对象可能更加困难,尤其是在 3D 世界中,因为单个对象可能存在于许多不同的位置和方向。
- 音频提示在某些游戏中,动作和事件伴随着独特的声音效果。可以通过监视游戏的音频输出并将其与相关音效的记录进行匹配来检测这些事件。一些游戏允许玩家为事件提供自己的音效,这允许使用旨在易于聆听和过滤的音效。
- 内存监控如果对游戏的内部运作有很好的了解,那么您可以通过检查游戏的内存空间来监控游戏的状态。一些控制台系统的作弊工具(例如Game Genie)使用这种方法。通过检测游戏更新了哪些内存,就可以检测到游戏在做什么。一些游戏在每次启动时都会随机分配它们使用的内存位置,以试图阻止此漏洞。
- 数据包分析使用适当的驱动程序,您可以拦截游戏的数据包,因为它们发送到您的网卡或从您的网卡检索(对于在线玩的游戏)。 对这些数据包的分析可以揭示您的游戏客户端正在与服务器通信的内容,这通常围绕玩家/敌人的行为展开。
- 游戏脚本一些游戏有一个内置的脚本界面。如果可用,这通常是最简单的方法,因为这是游戏软件的设计目标(以前的方法通常都算作“黑客”)。有些脚本必须在游戏中运行(通过控制台或通过附加系统),有些可以由外部程序运行,这些程序通过已发布的 API 通过游戏进行通信。
Generating input events back into the game is typically the easier task. Some methods include:
将输入事件生成回游戏通常是更容易的任务。一些方法包括:
- Memory "Poking"Similar to the memory monitoring section above, memory poking is the act of writing data directly into the game's memory space. This is the method used by the Game Genie for applying its cheat codes. Given the complexity of modern games, this is a very difficult task and can potentially crash the entire game.
- Input Emulation"Fake" keyboard or mouse signals can be generated in lieu of direct human interaction. This can be done in software using tools such as AutoIt. Hardware hacks can also be used, such as devices that connect to the computer's USB or PS/2 port and appear to the system to be a keyboard, but instead generate fake keypress events based on signals received from the computer (for instance, over a serial port). These methods can be harder for games to detect.
- Game ScriptingAs mentioned above, some games provide built-in methods for controlling it programmatically, and taking advantage of those tools is usually the easiest (but perhaps not the most powerful) technique.
- 内存“戳”类似于上面的内存监控部分,内存戳是将数据直接写入游戏内存空间的行为。这是 Game Genie 用于应用其作弊码的方法。鉴于现代游戏的复杂性,这是一项非常艰巨的任务,可能会导致整个游戏崩溃。
- 输入仿真可以生成“假”键盘或鼠标信号来代替直接的人机交互。这可以使用AutoIt等工具在软件中完成。也可以使用硬件黑客,例如连接到计算机的 USB 或 PS/2 端口并在系统看来是键盘的设备,但根据从计算机接收到的信号(例如,通过串行端口)。这些方法对于游戏来说可能更难检测。
- 游戏脚本如上所述,一些游戏提供了以编程方式控制它的内置方法,利用这些工具通常是最简单(但可能不是最强大)的技术。
Note that running a 'bot' in a game is usually a violation of the game's Terms Of Use and can get you suspended, banned, or worse. In some jurisdictions, this may carry criminal penalties. This is another plus for using a game's built-in scripting capabilities; if it's designed to be a part of the game software, then the game publisher is most likely not going to prohibit you from using it.
请注意,在游戏中运行“机器人”通常会违反游戏的使用条款,可能会导致您被暂停、禁止或更糟。在某些司法管辖区,这可能会导致刑事处罚。这是使用游戏内置脚本功能的另一个优点;如果它被设计为游戏软件的一部分,那么游戏发行商很可能不会禁止您使用它。
回答by Meinersbur
Once I wrote a simple MMORPG bot by myself. I used AutoHotkey.
曾经我自己写了一个简单的 MMORPG 机器人。我使用了AutoHotkey。
- It provides lots of methods to simulate user input -- one will work. It's tedious to program a working one in C++ by oneself (Or look into AutoHotkey's source).
- It can directly search the screen for pixel patterns, even game screens (DirectX)
- 它提供了许多模拟用户输入的方法——其中一种方法可行。自己用 C++ 编写一个工作程序很乏味(或者查看 AutoHotkey 的源代码)。
- 它可以直接搜索屏幕像素图案,甚至游戏屏幕(DirectX)
So what I did was to search the screen for the name of an enemy (Stored as a picture with the game's font) and the script clicks a few pixel below it to attack. It also tracks the health bar and pots if it is too low.
所以我所做的是在屏幕上搜索敌人的名字(存储为带有游戏字体的图片),然后脚本点击它下方的几个像素进行攻击。如果它太低,它还会跟踪健康栏和罐子。
Very trival. But I know of an WoW bot that is also made using AutoHotkey. And I seelots of other people had the same idea (Mine was not for WoW, but probably illegal, too).
非常琐碎。但我知道 WoW 机器人也是使用 AutoHotkey 制作的。而且我看到很多其他人也有同样的想法(我的不是为了魔兽世界,但也可能是非法的)。
More advanced techniquesdo not capture the screen but directly read the game's memory. You have to do a lot of reverse engineering to make this work. And it stops working when the game is updated.
回答by dash-tom-bang
How does an individual person go about their day to day?
一个人的日常生活是如何度过的?
This is sort of the problem that AIs in games solve.
这就是游戏中的人工智能解决的问题。
What do you want your entity to do? Code your entity to do that. If you want your monster to chase the player's avatar, the monster just needs to face the avatar and then move toward it. When that monster gets within a suitable distance, it can choose to bite the player avatar, and this choice can be as simple as AmICloseEnough(monster, player);
or more complex or even random.
您希望您的实体做什么?编码您的实体来做到这一点。如果你想让你的怪物追逐玩家的分身,怪物只需要面对分身然后朝它移动即可。当那个怪物进入合适的距离时,它可以选择咬住玩家分身,这个选择可以是简单的,也可以是AmICloseEnough(monster, player);
复杂的,甚至是随机的。
Bots in an FPS are tricky to get right because it's easy to make them perfect but not so easy to make them fun. E.g. they always know exactly where the player is (gPlayer.GetPosition()
) so it's easy to shoot the player in the head every time. It takes a bit of "art" to make the bot move like a human would.
FPS 中的机器人很难做到正确,因为让它们变得完美很容易,但让它们变得有趣却不容易。例如,他们总是确切地知道玩家在哪里 ( gPlayer.GetPosition()
),因此每次都很容易朝玩家的头部开枪。让机器人像人类一样移动需要一点“艺术”。
回答by dash-tom-bang
For FPS-style bots, you could take a look at the Unreal Development Kit. As I understand it, this has got a lot of the actual game source code.
对于 FPS 风格的机器人,您可以查看 Unreal Development Kit。据我了解,这有很多实际的游戏源代码。
回答by Ryan
bta gave a very good reply. I just wanted to add on saying that the different methods are suspectible to different means of detection by the gaming company. Hacking into the game client via memory monitoring or packet analysis generally is more easily detectable. I generally don't recommend it since you can get caught very easily.
bta 给出了很好的答复。我只是想补充说,不同的方法对游戏公司的不同检测手段产生了怀疑。通过内存监控或数据包分析入侵游戏客户端通常更容易被检测到。我通常不推荐它,因为你很容易被抓住。
Screen-scraping used with input emulation is generally the safest way to bot a game and not get caught. Many people, (myself included) have been doing it for years with no problems.
与输入仿真一起使用的屏幕抓取通常是使游戏机器人化而不被发现的最安全方法。许多人(包括我自己)多年来一直在这样做,没有任何问题。
In addition, to add an additional step between detecting what's going on in the game and providing input, some games require extensive calculation before you can decide what kind of input to provide to the game. For example, there was a game where I had to calculate the number of ships to send when attacking the enemy, and this was based on the number of ships I had, the type of ships, and who and what kind of enemy it was. The calculation is generally the "easy" part since you can do that usually in almost any programming language.
此外,为了在检测游戏中发生的事情和提供输入之间增加一个额外的步骤,一些游戏需要大量计算才能决定向游戏提供什么样的输入。例如,有一个游戏,我必须计算攻击敌人时要发送的船只数量,这是根据我拥有的船只数量,船只的类型以及敌人的种类和类型来计算的。计算通常是“简单”的部分,因为您通常可以使用几乎任何编程语言进行计算。
回答by Vasanth
As I see bots are real killer across various games / gambling industry. Hackers use bots to play on their behalf and this poses serious trust factor to other humans who don't get into malpractices. As Ryan mentioned the smartest bots use screen-scraping but I disagree to his point that screen-scraping bots cannot be caught. There are multiple screen scraping prevention service that includes ShieldSquare.
正如我所见,机器人是各种游戏/赌博行业的真正杀手。黑客使用机器人来代表他们玩游戏,这对其他没有参与不当行为的人构成了严重的信任因素。正如 Ryan 提到的,最聪明的机器人使用屏幕抓取,但我不同意他的观点,即无法捕获屏幕抓取机器人。有多种屏幕抓取预防服务,包括ShieldSquare。
Disclaimer: I'm one of the co-founder of ShieldSquare
免责声明:我是 ShieldSquare 的联合创始人之一
回答by BRampersad
It's called AI (artificial intelligence) and really isn't that hard to replicate, a set of rules and commands in the programming language of your game will do the trick. For example a FPS bot would work by getting the coordinates of your player's body and setting your enemy bot's gun to aim at that coordinate and start shooting when in a certain range.
它被称为 AI(人工智能)并且真的不难复制,您游戏的编程语言中的一组规则和命令将起作用。例如,FPS 机器人将通过获取玩家身体的坐标并将敌人机器人的枪设置为瞄准该坐标并在特定范围内开始射击来工作。