Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe-TheBro committed Aug 26, 2024
0 parents commit f64d745
Show file tree
Hide file tree
Showing 715 changed files with 3,251 additions and 0 deletions.
162 changes: 162 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2024] [Joe P. Hammond]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Elden Ring Rune Farming (ERRF)

## Table of Contents
- [Description](#description)
- [Directory](#directory)
- [How It Works](#how-it-works)
- [Usage](#usage)
- [Disclaimer](#disclaimer)
- [License](#license)

##
### Description
This program is designed to automate the process of farming runes in Elden Ring. It uses YOLO (You Only Look Once) object detection to detect state ingame and perform actions accordingly. As an aside, this project was made quickly and is not perfect. It is a proof of concept and should be used as such. I will take issues and pull requests, but I will not be actively maintaining this project. If you would like to maintain this project, please contact me.
#### P.S.
I started to implement a GUI for this project due to some async issues with the current implementation. I will not be finishing the GUI, but I will leave the code in the repository for anyone who would like to finish it.
### Directory
```
.
├── README.md
├── eldenring-detect.pt
├── eldenring-detect-v4.pt
├── main_ui.py
├── main.py
├── main.tcss
├── /screenshots
├── /arduino
└── /data
├── /raw
├── /util
├── test_model.py
├── /yolo
└── train.py
```
- `README.md` - This file.
- `eldenring-detect.pt` - The YOLO model used for object detection.
- `main.py` - The main program.
- `/screenshots` - Screenshots used for this file.
- `/arduino` - Arduino code for the controller.
- `/data` - Data used for training the YOLO model.
- `/raw` - Raw data used for training.
- `/util` - Utility functions for data processing.
- `test_model.py` - Test the YOLO model.
- `/yolo` - Different iterations of the data with labels and separation of training and testing data.
### How It Works
The program uses the YOLO model to detect the state of the game. Then depending the what the state the character is in will choose an action such as opening the map, walking, or using a skill. The program will then wait for the action to be completed and continue in the cycle based on the previous state. The program will continue to loop until the user stops the program. Example diagram below.
```mermaid
graph LR
MapState -->|Open Grace Menu| UseGrace
UseGrace -->|Wait| CheckState
CheckState -->|Character Detected| CharacterState
CharacterState --> MoveToLocation
MoveToLocation --> ActivateSkill
ActivateSkill -->|Wait| OpenMap
OpenMap --> MapState
```
### Usage
First, in Eldenring certain settings need to be set in order for the program to work. The settings are as follows:
- Under the `Game` tab, ensure that `Toggle Auto Lock-On` is set to `Off`, and that `Auto-Target` is set to `On`.
![](md-images/eldengameoptions.png)
- Under the `Camera` tab, set `Camera Auto Rotation` to `Off`.
![](md-images/eldencameraoptions.png)
- If you have changed the default bindings for keyboard and mouse, you will need to change them to back to default. The program uses the default bindings for the game.

To use this program, you'll need to either install the packages in the `environment.yml` file or run something like `conda env create --name envname --file=environment.yml`. This will create a conda environment with the necessary packages.

After installing the necessary packages, you'll need to run the program with the following command `python main.py #`. The `#` is the number indicting the type of farm route you would like to use. The options are as follows:
- `1` - Boulder farm route.
- `2` - Ritual Sword route. Requires a mouse input device that can be controlled via the arduino, I used https://www.amazon.com/AmazonBasics-3-Button-Wired-Computer-1-Pack/dp/B005EJH6RW
<img src="md-images/mousepcb.jpg" height=362><img src="md-images/arduinopcb.jpg" width=500>


### Disclaimer
I am not responsible for any bans or other consequences that may arise from using this program. Use at your own risk.
### License
The license can be found in the `LICENSE.md` file.
106 changes: 106 additions & 0 deletions arduino/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <Keyboard.h>

void setup()
{
// Begin serial communication at 9600 baud rate
Serial.begin(9600);
// Wait for the computer to set up the connection
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB
}
// Initialize keyboard emulation
Keyboard.begin();
}

void loop()
{
// Check if data is available to read from the serial port
if (Serial.available() > 0)
{
String data = Serial.readStringUntil(';');
handleKeyboardCommand(data);
}
}

void handleKeyboardCommand(String data)
{
// Split the data into the key and duration parts
int separatorIndex = data.indexOf(',');
if (separatorIndex != -1)
{
String keyStr = data.substring(0, separatorIndex);
String durationStr = data.substring(separatorIndex + 1);
int duration = durationStr.toInt();
int modifierSepKeyStr = keyStr.indexOf('_');
if (modifierSepKeyStr == -1)
{
for (int i = 0; i < keyStr.length(); i++)
{
Keyboard.press(keyStr.charAt(i));
}
delay(duration);
Keyboard.releaseAll();
Serial.println("1");
return;
}
String keyStrVal = keyStr.substring(0, modifierSepKeyStr);
String keyStrMod = keyStr.substring(modifierSepKeyStr + 1);

int horse = 0;
int horseSepKeyStr = keyStrMod.indexOf('^');
int sprint = 0;
int sprintSepKeyStr = keyStrMod.indexOf('!');
int skill = 0;
int skillSepKeyStr = keyStrMod.indexOf('$');

if (horseSepKeyStr != -1) {
horse = 1;
}

if (sprintSepKeyStr != -1) {
sprint = 1;
}

if (skillSepKeyStr != -1) {
skill = 1;
}

if (horse == 1) {
char menuKey = 'e';
char selectKey = KEY_DOWN_ARROW;
Keyboard.press(menuKey);
delay(200);
Keyboard.press(selectKey);
delay(100);
Keyboard.releaseAll();
delay(duration);
Serial.println("1");
return;
}

// skill requires use of a input device controlled by pin 8, once the pin is high the button is pressed, once the pin is low the button is released
if(skill == 1) {
// by default ashes of war are bound to Shift + pin 8
Keyboard.press(KEY_LEFT_SHIFT);
digitalWrite(8, HIGH);
delay(duration);
digitalWrite(8, LOW);
Keyboard.releaseAll();
Serial.println("1");
return;
}

if (sprint == 1)
{
Keyboard.press(KEY_LEFT_SHIFT);
for (int i = 0; i < keyStrVal.length(); i++) {
Keyboard.press(keyStrVal.charAt(i));
}
delay(duration);
Keyboard.releaseAll();
Serial.println("1");
return;
}
}
}
18 changes: 18 additions & 0 deletions arduino/test_mouse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
int switchPin = 8; // Pin connected to the base of the transistor

void setup()
{
pinMode(switchPin, OUTPUT);
digitalWrite(switchPin, LOW); // Start with the switch off
}

void loop()
{
// To connect the two points
digitalWrite(switchPin, HIGH);
delay(1000); // Keep them connected for 1 second

// To disconnect the two points
digitalWrite(switchPin, LOW);
delay(1000); // Keep them disconnected for 1 second
}
Binary file added data/raw/20230717231045_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20230721002859_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20230723022125_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20230723022147_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20230723022155_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220716_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220722_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220726_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220730_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220733_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220736_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220823_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220824_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220828_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220828_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220831_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220835_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220839_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220912_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220915_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220916_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220919_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220920_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220924_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220925_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/raw/20240519220927_1.jpg
Binary file added data/raw/20240519220927_2.jpg
Binary file added data/raw/20240519220930_1.jpg
Binary file added data/raw/20240519221039_1.jpg
Binary file added data/raw/20240519221109_1.jpg
Binary file added data/raw/20240519221111_1.jpg
Binary file added data/raw/20240519221114_1.jpg
Binary file added data/raw/20240519221116_1.jpg
Binary file added data/raw/20240519221129_1.jpg
Binary file added data/raw/20240519221130_1.jpg
Binary file added data/raw/20240519221131_1.jpg
Binary file added data/raw/20240519221132_1.jpg
Binary file added data/raw/20240519221133_1.jpg
Binary file added data/raw/20240519221134_1.jpg
Binary file added data/raw/20240519221135_1.jpg
Binary file added data/raw/20240519221137_1.jpg
Binary file added data/raw/20240519221144_1.jpg
Binary file added data/raw/20240519221148_1.jpg
Binary file added data/raw/20240519221152_1.jpg
Binary file added data/raw/20240519221155_1.jpg
Binary file added data/raw/20240519221158_1.jpg
Binary file added data/raw/20240519221201_1.jpg
Binary file added data/raw/20240519221204_1.jpg
Binary file added data/raw/20240519221210_1.jpg
Binary file added data/raw/20240519221215_1.jpg
Binary file added data/raw/20240519221219_1.jpg
Binary file added data/raw/20240519221224_1.jpg
Binary file added data/raw/20240519221229_1.jpg
Binary file added data/raw/20240519221250_1.jpg
Binary file added data/raw/20240520201505_1.jpg
Binary file added data/raw/20240527161404_1.jpg
Binary file added data/raw/20240527161408_1.jpg
Binary file added data/raw/20240527161412_1.jpg
Binary file added data/raw/20240527161415_1.jpg
Binary file added data/raw/20240527161418_1.jpg
Binary file added data/raw/20240527161420_1.jpg
Binary file added data/raw/20240527161423_1.jpg
Binary file added data/raw/20240527161426_1.jpg
Binary file added data/raw/20240527161429_1.jpg
Binary file added data/raw/20240527161433_1.jpg
Binary file added data/raw/20240527161436_1.jpg
Binary file added data/raw/20240527161439_1.jpg
Binary file added data/raw/20240527161442_1.jpg
Binary file added data/raw/20240527161446_1.jpg
Binary file added data/raw/20240527161507_1.jpg
Binary file added data/raw/20240527161507_2.jpg
Binary file added data/raw/20240527161510_1.jpg
Binary file added data/raw/20240527161512_1.jpg
Binary file added data/raw/20240527161515_1.jpg
Binary file added data/raw/20240527161517_1.jpg
Binary file added data/raw/20240527161520_1.jpg
Binary file added data/raw/20240527161523_1.jpg
Binary file added data/raw/20240527161525_1.jpg
Binary file added data/raw/20240527161529_1.jpg
Binary file added data/raw/20240527161533_1.jpg
Binary file added data/raw/20240527161612_1.jpg
Binary file added data/raw/20240527161614_1.jpg
Binary file added data/raw/20240527161617_1.jpg
Binary file added data/raw/20240527161620_1.jpg
Binary file added data/raw/20240527161624_1.jpg
Binary file added data/raw/20240527161628_1.jpg
Binary file added data/raw/20240527161630_1.jpg
Binary file added data/raw/20240527161637_1.jpg
Binary file added data/raw/20240527161652_1.jpg
Binary file added data/raw/20240527161658_1.jpg
Binary file added data/raw/20240527161703_1.jpg
Binary file added data/raw/20240527161707_1.jpg
5 changes: 5 additions & 0 deletions data/test_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ultralytics import YOLO
from PIL import ImageGrab
screenshot = ImageGrab.grab()
model = YOLO("../eldenring-detect.pt")
res = model.predict(screenshot, save=True)
Loading

0 comments on commit f64d745

Please sign in to comment.