A bot that can perform simple visual pattern matching and play back gamepad macros, split into:
bot_vision
, which implements aBotView
class, containing some potentially useful functions for more complicated bots.macro_handler
, which contains functionality to record macros from an XInput gamepad, convert them to VJoy-readable states, and play these converted macros back on a VJoy device.- three instances of bot classes inheriting from the
BotView
class, namedevaluator_bot
(which implementsEvaluatorBot
),level_logger
(which implementsLevelLogger
), andseed_finder
(which implementsSeedFinder
).
And a trivial run script.
- VJoy 2.1.8 (and perhaps later) (http://vjoystick.sourceforge.net)
- OpenCV (https://opencv.org/)
- pywin32
- For macro recording and playback:
- PYXInput (used to record manual XInput macros) (https://github.com/bayangan1991/PYXInput)
- my fork of pyvjoy (allows for synchronous vjoy device update) (https://github.com/dkhachatrian/pyvjoy)
- XOutput (wraps vjoy device as XInput device) (https://github.com/csutorasa/XOutput)
- Install via pip (or PyPI):
pywin32
,opencv-python
,pyxinput
- Install VJoy (and reboot as necessary). Ensure the first virtual device has enough buttons to map all XInput buttons (16 is plenty).
- Download XOutput -- v3.6 recommended to allow dropdown menu for vJoy buttons -- a bit less of a pain to configure. Place in separate folder. (Also install the ViGeM framework for the wrapper to work.)
- If configuration refuses to save through the program itself, you'll have to manually adjust the
settings.txt
file it generates when you click "Save Configuration". And example configuration is in theexample_configs
folder. This example configuration should would with the current setup inmacro_handler.py
. (Thesettings.txt
generated by the unpackedXOutput.exe
will have an HID for the vJoy device in the parenthesis instead of an ellipsis.)
- If configuration refuses to save through the program itself, you'll have to manually adjust the
- Place the version of pyvjoy linked above into your Python's library directory (or really anywhere in your Python's path). Also place
vJoyInterface.dll
(x86 or x64 depending on your OS), from the VJoy SDK, into thepyvjoy
directory.
The following need only be done when first recording the macros. Once the macros are saved, the bot scripts will handle vJoy device acquisition (assuming it's free), etc.
Import macro_handler
for all of this.
Currently, the vJoy buttons are mapped according to macro_handler.build_vjoy_button_mapping(xinput_buttons)
, which converts the one-hot bit vector into an integer (e.g. 0x04
-> 3, since it takes three rightward bit-shifts to convert the bit-vector to zero). You can see the exact mapping by inspecting macro_handler
's vjoy_buttons
.
You'll need a handle to your XInput device to record macros.
One way to test is calling macro_handler.test_controller_slot(slot_no)
and seeing if the output changes when you press buttons. If it works, respond positively to the prompt and it will return a handle to the XInput device.
Let's assume it's saved to a variable reader
. To record a macro, use macro_handler
's record_gamepad_reader
(read its docstring for specifics). This returns a dictionary. Save this macro into a dictionary of macros, giving it an intuitive name as its key (so you can refer to it more easily in your bot/playback).
(All example scripts and the below discussion assume the VJoy Device being set up is in the first slot: rID = 1
.)
On XOutput, set up the vJoy device's button mapping to match the settings in macro_handler.py
(check the vjoy_buttons
dictionary as necessary). Once the configuration is working, start the wrapper.
Acquire a vJoy device in Python via:
controller = pyvjoy.VJoyDevice(rID=1)
And run/test your macro with macro_handler.run_macro(controller, macro_dict)
.
After all of this, you can create a Python script and implement a class that extends from bot_vision.BotVision
, wire in what window to be looking at, and code the bot's logic. Example bots can be found in the example_bots
folder. (Note that the scripts expect to be in the same directory as bot_vision.py
and macro_handler.py
.)