Garry's Mod Demo parser

Messages
2,810
Reaction score
4,515
Points
845
TLDR: huge nerd thread. I can read the content of .dem files and can/want to play them in a player or do something cool with them. What would you like?

Some of you might remember that years ago I made a sloppy attempt of making my own version of Shadowplay tailormade to PERP. Remember PlaysTV that recorded your in-game deaths, kills and such automatically? That was pretty cool and pretty handy. It was called Rezerg but i never got around to finishing that project. I kinda wanted a PlaysTV style editor where you could see your deaths, kills, maybe even radio panics on a video editing timeline and it would let you easily create clips. Or search on a specific event and the tool would spit you out a video so you could use this right away. My skills at that time were inadequate and I didn't exactly have time on my hands. Considering I am a single human being this year I now have plenty of time! I also discovered AI assisted coding, so me and my good friend qwen3.8 running on a local install on my laptop got to work. No drinking water was harmed in the making of this ;)

Smeris, what the fuck are you talking about?
The process of watching a demo is incredibly tedious. It is slow, buggy and you cannot really fastforward or rewind easily. a demo, or .dem file stores networking information. Essentially, everything the perpheads server is telling you (move this entity over there, receive this voice message, john lennon just joined the server) is recorded to a file exactly like your game client is receiving it and rendering it you so. It also includes transmitted voice chat, lua code and the whole works. Anyone with a perpheads.dem file will see exactly the same information as you playing it even if they have never heard of perp. https://dem.nekz.me/ is a cool little insight of the content of a dem file

Because it is an encapsulation of network traffic a dem file is quite high level. It is a bitstream of events, messages and there are a bunch of tables. They are not exactly designed to be read by humans and they are bit packed so reading it is simply a nightmare. It's not a silly little json you can read in notepad. This is where i used AI assistance because aint nobody got time to decompile a large part of source engine networking with fuckall documentation. A few already did this for csgo/portal and this was a HUGE help. Although I would love to learn this at some point, there's only 26 weekends a year where I don't work :)




An example of a playermodel being loaded
raw


Current features:
I wrote a generic gmod parser and I'm writing a seperate, specific one for Perpheads. The perpheads one is not open source.
The features of the generic parser are as follows:
- voice chat's are converted to .wav in format of STEAM64_tickrate.wav
- Player XYZ and players camera rotation XYZ are stored in JSON format including metadata like playermodel and current weapon holding
- Only changed ticks logged per player to prevent json getting overly large.
- chat messages are logged
- entities like cars and props are logged
- doors opening/closing are logged


What you actually might care about
I'm a little conflicted on what to do next. I have a couple idea's with each and everyone having an advantage or drawback.

Idea 1:
A (web-based) tool where you can upload a .dem file, play it back in real-time and manipulate it. You could also convert it to a .mp4 Similar tools already exist for Counter Strike 2 https://cs2.cam/ This is going to be incredibly tedious because every bit of perpheads content would need to be cloned one-on-one into some form of a engine. There's plenty of tools to aid in this, but it would be the coolest outcome in the end for me. I already have a concept of an interpreter of a .dem that works on web but it's ai slop and just reads game events, player x,y and voice chat...

Idea 2:

Use this data for a perpheads variant of PlaysTV where shadowplay style clips can be fed data from a demo. This isn't really exciting, as this data can also be caught (much more easily!) with some injected lua or a dll. On behalf of the anticheat I advise you to not try this at home.

Idea 3:
A source engine based tool to play back a .dem file and convert it. I tried a bunch of tricks to have Garry's mod itself render a demo but i never got it to be faster than 0.5x real time. This would probably be less hassle but also less optimised.

idea 4: Do you have an idea please let me know my brain is very fried

Peak efficiency

A 15 minute demo is parsed in roughly 3.6 seconds - this is with voice and lua parsing enabled.
raw

Example data:
1787705675722.png


Try it yourself! I'm sure something will be broken on your end. Me or my lovely assistant will fix that



raw
This product was made in collaboration with my machines. There was a lot of elaborate prompting, custom GPT's, automatic media creation, reviewing, rewriting and/or reprompting. A part of code has been manually written by human and may or may not have been corrected by machines.


.​
GenAI Disclaimer - https://mmmlabel.tech
 
Last edited:
I kinda wanted a PlaysTV style editor where you could see your deaths, kills, maybe even radio panics on a video editing timeline and it would let you easily create clips.
In regards to seeing local player kills, I am unsure if this is possible. "entity_killed" is never fired, seeing as the client does not request it via the game event system. You can technically archive deaths by logging the initialisation of ragdolls, but I do not think it is possible to see who killed who. This data, from my understanding, is never sent to the client.

Regardless, this is pretty awesome. I've made a handful of demo parsers with the intent to trim demos for faster replay and logging console commands/CUserCmds sent. I never got this far though.
 
Back
Top