LET ME PLAY GTA:SA! Chaos using circuit python
Tags: python
Published: 2020-06-21 13:53:51

For those who don't know what chaos mod is, here goes a little definition -
> Every 30 seconds the game will trigger a random effect. This effect can be anything from giving you an RPG to exploding all nearby vehicles or making every nearby ped dance.

_Source : https://www.gta5-mods.com/scripts/chaos-mod-v-beta_

We are going to inject keyboard strokes using Adafruit's Circuit Python Express board (yea those cute circular boards with LEDs all over it :P). [I've published a project in past that makes use of this same technique, so for a basic understanding you can check that out!](https://www.hackster.io/p5g41tmlx/rubber-python-f0d023)

Ofcourse we can only inject cheat codes because of hardware limitations ¯\\\_(ツ)_/¯. So a basic roadmap for this code will be to make a list out of all cheat codes of GTA-SA and then randomly choose a cheat code from the list and then inject that. Now because that is a list so it's kind of a universal chaos mod.

A quick google search for cheat codes landed me to [this](https://www.ign.com/wikis/grand-theft-auto-san-andreas/Cheat_Codes_and_Secrets) page, so I'll just use some IDE magic to transform it to a list. Here is the list :

```python
[
"HESOYAM", "BAGUVIX", "CVWKXAM", "LXGIWYL", "PROFESSIONALSKIT",
"UZUMYMW", "STICKLIKEGLUE", "ANOSEONGLASS", "FULLCLIP",
"TURNUPTHEHEAT", "TURNDOWNTHEHEAT", "BTCDBCB", "BUFFMEUP",
"KVGYZQK", "AEZAKMI", "BRINGITON", "WORSHIPME", "HELLOLADIES",
"VKYPQCF", "PROFESSIONALKILLER", "NATURALTALENT", "SPEEDITUP",
"SLOWITDOWN", "AJLOJYQY", "BAGOWPG", "FOOOXFT",
"GOODBYECRUELWORLD", "BLUESUEDESHOES", "BGLUAWML", "LIFESABEACH",
"ONLYHOMIESALLOWED", "BIFBUZZ", "NINJATOWN", "BEKKNQV",
"CJPHONEHOME", "KANGAROO", "STATEOFEMERGENCY", "CRAZYTOWN",
"SJMAHPE", "ROCKETMAYHEM", "CPKTNWT", "WHEELSONLYPLEASE",
"ZEIIVG", "YLTEICZ", "LLQPFBN", "IOWDLAC", "EVERYONEISPOOR",
"EVERYONEISRICH", "CHITTYCHITTYBANGBANG", "FLYINGFISH", "JCNRUAD",
"SPEEDFREAK", "BUBBLECARS", "OUIQDMW", "GHOSTTOWN", "FVTMNBZ",
"BMTPWHR", "ROCKETMAN", "IWPRTON", "AIYPWZQP", "OLDSPEEDDEMON",
"JQNTDMH", "VROCKPOKEY", "VPJTQWV", "WHERESTHEFUNERAL",
"CELEBRITYSTATUS", "TRUEGRIME", "RZHSUEW", "JUMPJET", "KGGGDKP",
"OHDUDE", "FOURWHEELFUN", "AMOMHRER", "ITSALLBULL",
"FLYINGTOSTUNT", "MONSTERMASH", "PLEASANTLYWARM", "TOODAMNHOT",
"ALNSFMZO", "AUIFRVQS", "CFVFGMJ", "YSOHNUL", "NIGHTPROWLER",
"OFVIAC", "SCOTTISHSUMMER", "CWJXUOC"
]
```

And here is the full code :

```python
from adafruit_circuitplayground.express import cpx
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
import usb_hid
from time import sleep
from random import choice

kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)

CHEATS = [
"HESOYAM", "BAGUVIX", "CVWKXAM", "LXGIWYL", "PROFESSIONALSKIT",
"UZUMYMW", "STICKLIKEGLUE", "ANOSEONGLASS", "FULLCLIP",
"TURNUPTHEHEAT", "TURNDOWNTHEHEAT", "BTCDBCB", "BUFFMEUP",
"KVGYZQK", "AEZAKMI", "BRINGITON", "WORSHIPME", "HELLOLADIES",
"VKYPQCF", "PROFESSIONALKILLER", "NATURALTALENT", "SPEEDITUP",
"SLOWITDOWN", "AJLOJYQY", "BAGOWPG", "FOOOXFT",
"GOODBYECRUELWORLD", "BLUESUEDESHOES", "BGLUAWML", "LIFESABEACH",
"ONLYHOMIESALLOWED", "BIFBUZZ", "NINJATOWN", "BEKKNQV",
"CJPHONEHOME", "KANGAROO", "STATEOFEMERGENCY", "CRAZYTOWN",
"SJMAHPE", "ROCKETMAYHEM", "CPKTNWT", "WHEELSONLYPLEASE",
"ZEIIVG", "YLTEICZ", "LLQPFBN", "IOWDLAC", "EVERYONEISPOOR",
"EVERYONEISRICH", "CHITTYCHITTYBANGBANG", "FLYINGFISH", "JCNRUAD",
"SPEEDFREAK", "BUBBLECARS", "OUIQDMW", "GHOSTTOWN", "FVTMNBZ",
"BMTPWHR", "ROCKETMAN", "IWPRTON", "AIYPWZQP", "OLDSPEEDDEMON",
"JQNTDMH", "VROCKPOKEY", "VPJTQWV", "WHERESTHEFUNERAL",
"CELEBRITYSTATUS", "TRUEGRIME", "RZHSUEW", "JUMPJET", "KGGGDKP",
"OHDUDE", "FOURWHEELFUN", "AMOMHRER", "ITSALLBULL",
"FLYINGTOSTUNT", "MONSTERMASH", "PLEASANTLYWARM", "TOODAMNHOT",
"ALNSFMZO", "AUIFRVQS", "CFVFGMJ", "YSOHNUL", "NIGHTPROWLER",
"OFVIAC", "SCOTTISHSUMMER", "CWJXUOC"
]

while True:
    sleep(30)
    layout.write(choice(CHEATS))
```

So this will just run a random cheat after every 30 seconds. Now I'll just make this look good by using the onboard LEDs. There are 10 of them so I can light one after every 3 seconds to make it look good.  Here's the code for that:

```python
from adafruit_circuitplayground.express import cpx
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
import usb_hid
from time import sleep
from random import choice
from adafruit_circuitplayground.express import cpx

cpx.pixels.brightness = 0.1

kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)

CHEATS = [
"HESOYAM", "BAGUVIX", "CVWKXAM", "LXGIWYL", "PROFESSIONALSKIT",
"UZUMYMW", "STICKLIKEGLUE", "ANOSEONGLASS", "FULLCLIP",
"TURNUPTHEHEAT", "TURNDOWNTHEHEAT", "BTCDBCB", "BUFFMEUP",
"KVGYZQK", "AEZAKMI", "BRINGITON", "WORSHIPME", "HELLOLADIES",
"VKYPQCF", "PROFESSIONALKILLER", "NATURALTALENT", "SPEEDITUP",
"SLOWITDOWN", "AJLOJYQY", "BAGOWPG", "FOOOXFT",
"GOODBYECRUELWORLD", "BLUESUEDESHOES", "BGLUAWML", "LIFESABEACH",
"ONLYHOMIESALLOWED", "BIFBUZZ", "NINJATOWN", "BEKKNQV",
"CJPHONEHOME", "KANGAROO", "STATEOFEMERGENCY", "CRAZYTOWN",
"SJMAHPE", "ROCKETMAYHEM", "CPKTNWT", "WHEELSONLYPLEASE",
"ZEIIVG", "YLTEICZ", "LLQPFBN", "IOWDLAC", "EVERYONEISPOOR",
"EVERYONEISRICH", "CHITTYCHITTYBANGBANG", "FLYINGFISH", "JCNRUAD",
"SPEEDFREAK", "BUBBLECARS", "OUIQDMW", "GHOSTTOWN", "FVTMNBZ",
"BMTPWHR", "ROCKETMAN", "IWPRTON", "AIYPWZQP", "OLDSPEEDDEMON",
"JQNTDMH", "VROCKPOKEY", "VPJTQWV", "WHERESTHEFUNERAL",
"CELEBRITYSTATUS", "TRUEGRIME", "RZHSUEW", "JUMPJET", "KGGGDKP",
"OHDUDE", "FOURWHEELFUN", "AMOMHRER", "ITSALLBULL",
"FLYINGTOSTUNT", "MONSTERMASH", "PLEASANTLYWARM", "TOODAMNHOT",
"ALNSFMZO", "AUIFRVQS", "CFVFGMJ", "YSOHNUL", "NIGHTPROWLER",
"OFVIAC", "SCOTTISHSUMMER", "CWJXUOC"
]

while True:
    for x in range(0,10):
        cpx.pixels[x] = (255,0,144)
        sleep(3)

    layout.write(choice(CHEATS))
    cpx.pixels.fill((0,0,0))
```

Hope you enjoyed this small project. [Check out my other projects on Hackster too :)](https://www.hackster.io/p5g41tmlx)

Shalom.