Generate PokemonGo RPC Protos to C#

2016/07/133 min read
bookmark this
Responsive image

Table of Contents

  1. How to Generate Pokemon Proto API to C# Types
  2. Download Google Protobuf
  3. Add Path to System Environment Variables
  4. Download Python
  5. Compile All the PokemonGO API Protos
  6. Output Result of C# Classes

Introduction

This blog demonstrates how to use Google Protocol Buffers and Python to generate PokemonGo API proto files into C# types.

How to Generate Pokemon Proto API to C# Types

The Pokemon API uses Google Protocol Buffers to generate API contracts in C#. This blog will demo how to do that. In the following demo, we'll use Protobuf's 3.0.0-beta-2 for C#. You can download it from the following link: Protobuf Release. Also, we'll need Python because POGOProtos needs Python to run the command to generate Protos to C#.

1. Download Google Protobuf

In this blog, I'm using the 3.0.0-beta-2 on my Windows 10. Once you download this to your PC, you'll also need to add the path to Environment Variables.

Add Path to System Environment Variables

Once you add the path, you can type protoc at the command line.

A:\protoc-3.0.0-win32\bin

The following is an example command to get the version of protoc:

> protoc --version

2. Download Python

You'll need Python, so go to the Python website to download it. Once you download Python, try not to change the default folder, and also add the path to the system Environment Variables as well.

C:\Python27
C:\Python27\Scripts

3. Compile All the PokemonGO API Protos

Once you have the Protos and Python, you can start to get what you really want, which is the PokemonGo Protos to call the Pokemon API. Go to the GitHub repo to get the latest source code.

You have a couple of options to compile Protos to C# here. I'm using the following command to compile all protos to C# classes. You will navigate to the location that contains compile.py, then run the following command:

python compile.py

Output Result of C# Classes

After running the command, you'll get all the C# classes in the output folder as shown below.

Conclusion

Generating PokemonGo RPC Protos to C# requires Google Protobuf and Python. Once you have both set up with the correct environment variables, running a single Python command generates all the C# classes needed to interact with the Pokemon API.