⚠️ EDUCATIONAL USE ONLY This project is created strictly for educational purposes to demonstrate WebSocket protocols, bot automation techniques, and GUI development with Python. Use of automation tools may violate the terms of service of Magic Garden. The authors do not condone or encourage the use of this software to gain unfair advantages in the game. Use at your own risk.
A bot for Magic Garden that connects via WebSocket, provides real-time game state visualization, and automates gameplay tasks.
pip install -r requirements.txtPyQt6 UI (Default):
python app.pyLaunches the modern PyQt6 interface with:
- VS Code Dark+ theme - Professional dark theme inspired by VS Code
- Fully responsive design - Resizable window and panels
- Garden visualization - Real-time garden grid with dynamic scaling
- Tabbed interface - Inventory, Pets, Shop, Journal, and Stats tabs
- Live console - Real-time bot activity logging
- Connection info - Player position and network statistics
Tkinter UI (Legacy):
python app.py --ui tkinterpython app.py --headlessRuns automation without GUI - perfect for running in background or on servers.
python app.py --room-id MG1Join a specific room instead of the default.
The bot uses a modular architecture:
app.py- Main entry pointconfig.py- Configuration management (loadsbot_config.json)game_state.py- Thread-safe game state managementnetwork/client.py- WebSocket client and connection handlingnetwork/protocol.py- Message processing and protocol logicautomation/- Automated gameplay modules:harvest.py- Auto-harvest and replant cropspets.py- Pet feeding and movementshop.py- Automatic seed/egg purchasing
ui/- User interface modules:qt_gui.py- Modern PyQt6 interface (default)qt_components/- Modular UI components (garden, inventory, pets, etc.)gui.py- Legacy Tkinter interface
utils/- Coordinate conversion, validation, etc.
- ✅ WebSocket connection - Full game protocol support
- ✅ Thread-safe state management - Proper locking for concurrent access
- ✅ Automatic message logging - All WebSocket traffic saved to
messages.log - ✅ Persistent player ID - Saved in
bot_config.json - ✅ Real-time updates - UI refreshes on every game state change
- ✅ Emulates browser behavior - Proper pings, pongs, position updates
PyQt6 UI (Default):
- ✅ VS Code Dark+ theme - Professional color scheme
- ✅ Component-based architecture - Modular, maintainable code
- ✅ Fully responsive - Dynamic window and panel resizing
- ✅ Garden visualization - Real-time grid with mutation indicators
- ✅ Tabbed interface - Inventory, Pets, Shop, Journal, Stats
- ✅ Copy-friendly panels - Content updates don't interrupt text selection
- ✅ Scroll preservation - Panel scroll position maintained during updates
Tkinter UI (Legacy):
- ✅ Three-panel layout - World view, Garden view, Stats/Inventory
- ✅ Simple interface - Lightweight alternative
✅ Auto-harvest - Automatically harvest mature crops, replant, and sell
- Enable/disable via config
- Configurable species list to auto-harvest
- Separate list for species that need replanting (perennials like Sunflower keep growing, annuals like Carrot/Tomato/Bamboo need replanting)
- Configurable minimum mutations (e.g., only harvest crops with 3+ mutations)
- Prioritizes highest mutation count when selling
- Harvests ALL ready plants of each species (not just one)
- Automatically sells all harvested crops after each cycle
- Configurable check interval
✅ Pet automation - Feed hungry pets and move them around garden
- Configurable food limits per species
- Random movement within garden bounds
✅ Shop automation - Auto-purchase seeds and eggs when low
- Configurable minimum stock levels
- Coin balance checking
The bot emulates proper client behavior:
- Connection - VoteForGame, SetSelectedGame, authentication
- Periodic - Ping/Pong (every 2s), PlayerPosition updates
- Gameplay - PlantSeed, Harvest, FeedPet, BuyItem, PetPositions
- State tracking - FullState, PartialState (JSON patches)
Edit bot_config.json to customize behavior:
{
"playerId": "your-persistent-id",
"cookies": "your-magicgarden.gg-cookies",
"ready_to_harvest": {
"enabled": true,
"species": ["Sunflower", "Bamboo", "Carrot", "Tomato"], // All species to auto-harvest
"species_to_replant": ["Carrot", "Tomato"], // Only replant annuals (perennials like Sunflower/Bamboo keep growing)
"min_mutations": 3, // Only harvest crops with 3+ mutations
"check_interval_seconds": 30 // Check for harvestable crops every 30 seconds
},
"pet_food_mapping": {
"Bee": ["Lily", "Daffodil"],
"Chicken": ["Aloe"],
"Worm": ["Aloe"]
},
"shop": {
"enabled": true,
"check_interval_seconds": 60,
"min_coins_to_keep": 1000,
"items_to_buy": {
"seeds": {
"enabled": true,
"items": ["Carrot", "Tomato"]
},
"eggs": {
"enabled": true,
"items": ["CommonEgg", "UncommonEgg"]
}
}
},
"reconnection": {
"max_retries": 5,
"base_delay": 5,
"max_delay": 60
}
}All WebSocket traffic is logged to messages.log:
- Sent and received messages
- Timestamps
- Full JSON payloads
- Protocol events (Welcome, PartialState, etc.)
Perfect for debugging and understanding the game protocol!