Inspiration

Many games have Twitch Integration built in which engaged viewers and chatters. Planet Zoo 2 unfortunately didn't, but is the perfect candidate for it.

What it does

There are 4 components:

  • A planet zoo 2 mod, which adds raffle functionality to the animal view, and communicates with a companion app (exports animal data, imports raffle data)
  • A companion app, which communicate with the planet zoo 2 mod, connects to Twitch Chat for receive raffle entries, and communicates with the backend that powers the Twitch extension
  • A backend hosted on cloudflare workers that servers data to the extension
  • A twitch extension that provides a list of animals in the zoo and their stats, as well as raffle information

When the streamer starts a raffle from in the game (using the mod), viewers in chat can type !enter for a chance to have the animal named after them.

When viewing the streamer, viewers can open the extension to see a list of all the animals in the zoo, along with their names and states.

Note: The extension requires approval of Twitch, which takes up to 2 weeks, so it's not publicly available yet

How we built it

I used codex to try and figure out and prototype the initial feasibility of the mod. Planet Zoo 2 locks down their LUA implementation so there's no easy way to communicate directly with e.g. Twitch. That's why I also built the companion app.

The mod is written in LUA and is ran by the game engine. The in-game UI is HTML/javascript. The companion app is a single .exe file for Windows built using Golang. It reads Twitch chat anonymously over IRC for the raffles, and sends zoo data to the backend.

The backend is plain javascript running on Cloudflare workers, and also has a landing page and privacy notice.

The twitch extension is just plain HTML, CSS and Javascript, with a mobile and desktop panel, plus the configuration.

I used my own experience as a software developer to finish the project, along with some additional help from Claude (where I have higher usage limits currently).

Challenges we ran into

Initially I was surprised by exactly how many components were required to make this all work (mod, companion app, backend, extension). Initially I was hoping to just be able to have a single mod in the game that handles everything.

Accomplishments that we're proud of

I'm proud with the workaround that was developed for allowing communication between Planet Zoo 2 and the companion app. The game engine is only capable of attempting to load files, it can't use HTTP or networking. We use Windows named pipes to communicate:

### How the named pipes work

The game's Lua can't open network connections or write files. It can only open and read a file (loadfile). Named pipes get around that: any program can create one without admin rights, \\.\pipe\<name> opens like a file, and the program that owns the pipe sees every open and chooses what the reader gets back.

The trick: which pipe the game opens is the data.

### The pipes

The companion creates 258 pipes at startup:

| Pipe | Meaning | |---|---| | \\.\pipe\zootwitch.begin | start of a message | | \\.\pipe\zootwitch.b00 … .bff | one byte each (256 pipes) | | \\.\pipe\zootwitch.end | end of message; the only pipe that replies |

### Mod → companion

To send hb n=44, the mod opens begin, then one pipe per byte (b68 h, b62 b, b20 space, …), then end. Each open blocks until the companion has recorded that symbol, so bytes always arrive in order.

### Companion → mod

Opening end returns a small Lua script, for example return {id=7, ok=true, cmd={...}, rf={...}}. The mod loads it with loadfile(path, "t", {}): text only and an empty environment, so it can only build data. The reply carries commands (such as renaming an animal), the raffle state for the in-game tab and box, and tuning values.

### Details

  • Repeated bytes: each pipe keeps a spare instance ready, so the same byte twice in a row doesn't wait.
  • No companion running: opening begin fails at once, and the mod drops the message without the game hanging.
  • Remote connections: the pipes refuse connections from other computers.

What we learned

AI can be used to create mods and extensions for games even when you think it's impossible.

What's next for Planet Zoo 2 mod, Twitch extension, chat integration

  • I'd love for it to get approved in Review, and continue to work on new features. Ideal future: The game developers see that Twitch Integration works well and implements it into the game itself.
Share this project:

Updates

Submission history