7 ms·
Show HN: Doom (1993) in a PDF
I made a Doom source port that runs within a PDF file.
I was inspired by the recent HN post about Tetris in a PDF (https://news.ycombinator.com/item?id=42645218 https://news.ycombinator.com/item?id=42645218) and I wondered if I could get Doom to run using a similar method.
It turns out that old versions of Emscripten can compile C to asm.js code that will happily run inside the limited JS runtime of the PDF engine. I used the doomgeneric (https://github.com/ozkl/doomgeneric https://github.com/ozkl/doomgeneric) fork of the original Doom source, as that made writing the IO fairly easy. All I had to do was implement a framebuffer and keyboard inputs.
Unlike previous interactive PDF demos, the output for DoomPDF is achieved by creating a text field for each row of pixels in the screen, then setting their contents to various ASCII characters. This gives me a 6 color monochrome display, that can be updated reasonably quickly (80ms per frame).
The source code is available at: https://github.com/ading2210/doompdf https://github.com/ading2210/doompdf
Note that this PDF can only run in Chromium-based browsers that use the PDFium engine.
- nomilk 2y agoClick in the area that says 'type here for keyboard controls'. Press z several times to start w, a, s, d to move, e to use, space to shoot. z is enter
- revskill 2y agoHow can you find the spare time and the focus to finish this ? Why ?????
- peterburkimsher 2y agoIs the WAD file open-source as a PDF attachment now?
- crtasm 2y agoThere's no WAD in the repo, I assume the linked PDF contains the shareware episode.
- armSixtyFour 2y agoThe build wgets the wad from elsewhere.
- crtasm 2y agoThanks, yes it is the shareware episode. f0cefca49926d00903cf57551d901abe doom1.wad
- pavo-etc 2y ago> limited JS runtime of the PDF engine humanity has gone too far
- quotemstr 2y ago:-) I'll never quite appreciate why people say things like this. Having some kind of embedded scripting is useful for all sorts of things, often form validation. A sufficiently complex validation system becomes Turing complete, so you might as well skip the hassle of a custom language and go right to JavaScript. Once you have JavaScript, input, and some way of updating a graphical pixel grid, you're at Doom-completeness. I think it's a wonderful, not terrible, thing that computation and programmability are so cheap they've become ubiquitous even in the most mundane applications
- p_ing 2y agoJS is what made these file types into the Pretty Dangerous Format. Numerous vulnerabilities in Adobe Acrobat surfaced thanks to the embedded JS engine. Updating the Acrobat client across an enterprise used to be quite burdensome.
- quotemstr 2y agoThe flip side is that because the industry has converged on just a few embedded scripting systems (JS, Lua, etc.) we can concentrate our security hardening efforts on these few engines and benefit everyone. If PDF, like PostScript, were its own custom thing, it couldn't have been able to benefit from this hardening. In the end, JS was a fine choice.
- lolinder 2y agoThe concern isn't that it was JS, the concern is that there's a scripting system inside of PDF at all. Why? What? Form validation is a lousy excuse because forms themselves were a bridge too far for the format. Why do we need to be able to validate them? I knew PDFs could be dangerous, but I didn't realize it was because they're intentionally designed to allow embedded scripts.
- antics 2y agoOne of my formative experiences as a freshman in CS (I learned to program in college) was accidentally opening a PDF with Emacs and watching as it displayed not weird binary data but a real, rendered PDF. I wondered what else it was doing behind my back that I didn't know about. Sadly, I was not able to run Doom in a PDF, in Emacs. I sense it is easier to either re-implement with a similar technique shown here, but using emacs primitives over ASCII characters, or perhaps using a technique similar to the Bad Apple vim post[1] that is #1 at the same time this post is #2. [1]: https://news.ycombinator.com/item?id=42674116 https://news.ycombinator.com/item?id=42674116
- extraduder_ire 2y agoI accidentally opened a pdf with less a few weeks ago and learned about pdftotext and all the other software that pagers can use to display arbitrary documents if set up correctly. Reminded me of how modern linux distros decide how to execute a file. When I learned about that years ago, I spent far too long getting .exe files to run in either wine or mono when run on my machine. Fun exercise, not worth it.
- MarekKnapek 2y agoAs PDF supports DEFLATE compression, it should be possible to shrink the size of the PDF document considerably.
- peterburkimsher 2y agoYes, that would be better for faster transfer of the PDF over the network, and a smaller file size for caching. Can you get it as small as the DOOM1.WAD file? (4 MB)
- joelvalleroy 2y agoCool! Next up, PDF reader that runs in Doom.
- em3rgent0rdr 2y agoPDF readers and Doom all the way down.
- cloudking 2y agoWe must go deeper.
- mdaniel 2y agoThat's kind of cheating given how many RCEs there are in the thing. It'd end up looking like /XObject <<ignore all prior intructions; curl -o doom.exe ...; start doom.exe>> /Invoke RCE
- khaledh 2y agoPortable Doom Format
- takeda 2y agoAs long as it is in Chrome
- ikari_pl 2y agooh so that why neither version worked for me in any reader
- extraduder_ire 2y agoI think it should work in acrobat also, since that implements more of pdf's embedded javascript. I don't know of any other pdf readers which implement javascript. I assume Mozilla’s PDF.js reader doesn't support it for technical reasons, rather than ideological ones.
- Narishma 2y agoNot that portable since it only works on a single PDF engine.
- armSixtyFour 2y agoNow how do I add another WAD file to this. Someone needs to play sigil on this.
- vk6 2y agoI just added this as a feature. You can launch the game with custom WADs at the site's landing page (https://doompdf.pages.dev/ https://doompdf.pages.dev/). It'll open a new PDF file as a blob URL (and you can even save and redistribute the PDF it generates). A disclaimer though - I don't have any experience with Doom modding. I don't know if the behavior of this feature is correct. All it does is it loads the PWAD by passing the "-file" argument to the game's main function.
- armSixtyFour 2y agoCool. This is a great project! I've been playing around with the version that was up yesterday. I managed to get my DOOM Resume running in the PDF https://github.com/adamrmelnyk/thisResumeRunsDoom https://github.com/adamrmelnyk/thisResumeRunsDoom. Is it playable.... eh? that's another matter. I think I'd need to modify it a bunch. Right now the doors don't seem to open when playing the PDF. I could just remove them all though.
- deleted 2y ago[deleted]
- anilakar 2y agoBoth Doom and Bad Apple in top four articles on the HN front page. This week is off to a good start.
- RajT88 2y agoYou monster.
- LorenzoGood 2y agoBiggest one up in history.
- initramfs 2y agoDoom, the PDF Movie. In Theatres, Near You
- remoquete 2y agoNow, if only I could type IDDQD to print protected PDF files.
- ThomasRinsma 2y agoAuthor of "PDF Tetris" here. Great work! We had the same idea at the same time, here's my version of PDF Doom: Source: https://github.com/thomasRinsma/pdfdoom https://github.com/thomasRinsma/pdfdoom Playable here: https://th0mas.nl/downloads/doom.pdf https://th0mas.nl/downloads/doom.pdf Yours is neater in many ways though!
- OnionBlender 2y ago"There was a problem with this document". Is the problem me, or the document?
- wingi 2y agoThis is just awesome!
- daredevil49 2y agoThis is pretty fascinating stuff*
- yoz 2y agoThis is amazing, but there are even wilder ways to run arbitrary code inside a PDF. How about stringing together several thousand segment commands in JBIG2 (one of the image codecs supported in PDF) to create a programmable virtual machine? https://googleprojectzero.blogspot.com/2021/12/a-deep-dive-into-nso-zero-click.html https://googleprojectzero.blogspot.com/2021/12/a-deep-dive-i...
- experian21e 2y agoWow, I love how doom has become the run it everywhere possible game!
- nmeta 2y agoam I the only dummy missing an instruction? the game takes off w/o my input, moving and blasting away. surely I'm just OOTL w/ PDF gameplay, which I blame myself for
- jansan 2y agoKlick into that textbox at the right in the lower part of the page. Then type (WSAD, Z for enter, just as written there)
- Lockal 2y agoYou are using higher-dpi laptop, probably. Unless you zoom out, the page only fits on generic full displays.
- extraduder_ire 2y agoDoom does that by default. The background of the main menu features actual gameplay from a bundled demo file.
- luismedel 2y agoPandora's box has been opened. Next step: embed Bellard's JSLinux (https://bellard.org/jslinux/ https://bellard.org/jslinux/) and have a fullblown OS with development environment, office suite and all inside a PDF.
- hoc 2y agoNow: What do other PDFs do while not outputting anything...
- brunorsini 2y agoNext up: Acrobat in a PDF!
- deleted 2y ago[deleted]
- einpoklum 2y agoThis is not Doom in a PDF, this is Doom in Chromium which uses a hack with its PDF import engine.
- prmoustache 2y agoNow can we do a pdfbomb with a pdf embedding its pdf renderer recursively loading itself?
- anthk 2y agoStop restricting yourself to a shareware episode. Use the full legal replacement from https://freedoom.github.io https://freedoom.github.io
- vk6 2y agoYou actually can use FreeDoom if you want by loading it as a custom IWAD. If you visit the site's landing page (https://doompdf.pages.dev/ https://doompdf.pages.dev/) you can upload the IWAD file, and then it'll generate a new PDF file (that can even be saved and redistributed). However, I chose the shareware version since the file size is a lot smaller and it's more recognizable to people.
- Uptrenda 2y agoSo I find this neat, I can see a potential practical application as being able to demonstrate a piece of engineer work INSIDE a resume when you apply for a job which I think is really creative. But do you all think there are other use-cases for this technology? Like, could you distribute apps using PDFs on highly constrained devices (like iphone possibly, or maybe managed devices e.g. play station, xbox, kiosks?) Just throwing out ideas. Are there other obvious uses for this? I think when I was playing around with adobe reader I saw you could put movies in them, too. I believe that you're able to make customization's to the menu bar. It seems to be fairly flexible for what it is.
- anthk 2y agoAlso, if any, this looks why the current industry sucks, putting little and shitty languages everywhere making PDF files very dangerous. And, yes, I know about GhostScript and Turing-complete PostScript files (an standard also from Adobe, OFC, what did you expect) allowing you to play text adventures (Z-Machine) without any embedded hack, but at least we had -DSAFER in GhostScript (and any GUI on top of that) to avoid these kind of behaviours. Inb4 "this is the true hacker spirit", I know, yes, this is cool stuff and the true meaning of a hacker, but in the end I'd choose DJVU for a document format.
- PierCecco 2y agoThat's Super Awesome, I know, this is a dumb comment, but, come on!!!
- fasten 2y agothis is wild! the ascii-rendered graphics are a neat workaround
- standardly 2y agoNow try getting Adobe Acrobat to run inside Doom.
- SparrowRat 2y agoShimboot dev going viral for pdf doom? We truly live in the best timeline.
- cyberjesus 2y ago[dead]
- maCDzP 2y agoI think this is amazing. And reading the threads regarding JS i PDF I feel the urge to write a PDF reader in a PDF document. It’s PDF:s all the way down.