Guillem96 / pokemon-trade-spoofer

Pokemon Trade Spoofer - Trade any Pokemon to GSC versions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pokemon GSC Trade Spoofer

Trade whatever Pokemon you want to your childhood Pokemon Gold/Silver/Crystal versions.

Desktop App Screenshot

Developer Guide πŸ‘¨πŸ»β€πŸ’»

Pokemon Trading State Machine 🎰

Pokemon trades involve a several amount of states (connecting with player, waiting in trade room, exchange random seed, etc...).

Managing those states and its associated behavior with if else statements is a pain in the ass. Engaging the developer to use bad practices and code smells like global states. Moreover, the code rapidly becomes hard and follow for people trying to go through it. Therefore, I decided to implement this logic of switching states and behaviors using a slight modification of the State pattern defined here.

State Machine Components:

  • State: Has a run method which implements the behavior of the according state and returns an instance of the next state. Additionally, the run method receives a Context object as a parameter.

  • Context: Contains the state machine shared information. In our case: the Pokemon to be traded, the received party from the other player, etc.

  • StateMachine: The state machine itself is the owner of the Context and keeps a reference to the current state. Every time, the State.run returns, the state machine manages the execution of the new state.

See in the image below the state machine implemented:

Frontend βš›

The frontend is a desktop application developed in electron. To communicate the electron frontend with the python package running the backends (BGB, ...), I developed a management REST API leveraging FastAPI (See section below).

The desktop application comes bundled with a Python executable build with PyInstaller. This Python executable is basically the pkm_trade_spoofer "packaged" with all dependencies so it can be run everywhere.

At launch, electron app spawns a process running the aforementioned Management API, then as usual, a window with a web interface (built with HTML, CSS and typescript) pops, so the user can easily interact with the Pokemon trade spoofer.

Check the implementation under the desktop-app directory.

Management API

This REST API provides an intuitive HTTP interface to manage the execution of the backends.

It only provides two endpoints:

  • /start-backend: Starts the execution of a backend.
  • /stop-backend: Gracefully stops the execution of a backend.

Check the implementation here.

Shout-out and credits

  • Thanks for the amazing write up on how to use BGB link cable data to emulate Pokemon R/B/Y trades.

  • BGB Link Server base implementation from Matt Penny

About

Pokemon Trade Spoofer - Trade any Pokemon to GSC versions


Languages

Language:Python 52.3%Language:TypeScript 45.7%Language:JavaScript 0.9%Language:Makefile 0.6%Language:HTML 0.2%Language:CSS 0.1%