How-to: convert Parchment game back to .blorb/.ulx/.z* game

Hi, I figured out a way to reverse the encoding process that makes an z-code/glulx game into a parchment .js game. I also made a shellscript (linux and unix / BSD and similar) to convert them and save a normal version to be used by your interpreter of choice.
I also have some tips on how to make it work with windows at the bottom of the post.
I thought I’d share.

Here’s the shellscript (a bit hackish but it works, updated to use curl for OS X compatibility):

[code]#! /bin/sh
#js2zcode - decode parchment game .js files
while getopts “:hd:” opt; do
case $opt in
h)
echo “js2zcode - decodes parchment game .js files”
echo “the .js file should start with ‘processBase64Zcode(’.”
echo “Usage:”
echo “-h Displays this help.”
echo “-d Use URL.”
echo “If none of these arguments are given, the only parameter is a local file name.”
echo “”
echo “Output file is always ‘game.blorb’.”
;;
d)
curl -s “echo $OPTARG” | sed “s/processBase64Zcode(’//g” | sed “s/=’)/=/g” | base64 --decode > game.blorb
echo “downloaded”
;;
?) ;;
esac
done

echo $1” is Probably a terrible way to implement this. Oh well.

if [ “$1” != “-h” ]; then
if [ “$1” != “-d” ]; then
if [ -z “$1” ]; then
echo “No arguments given.”
echo “js2zcode - decodes parchment game .js files”
echo “the .js file should start with ‘processBase64Zcode(’.”
echo “Usage:”
echo “-h Displays this help.”
echo “-d Use URL.”
echo “If none of these arguments are given, the only parameter is a local file name.”
echo “”
echo “Output file is always ‘game.blorb’.”
fi
if [ “$1” != “” ]; then
echo “-d argument not given; Using local file.”
cat “echo $1” | sed “s/processBase64Zcode(’//g” | sed “s/=’)/=/g” | base64 --decode > game.blorb
echo “Done! Try running game.blorb with your interpreter now.”
fi
fi
fi[/code]
The below uses wget and is the original version I posted.

[code]#! /bin/sh
#js2zcode - decode parchment game .js files
while getopts “:hd:” opt; do
case $opt in
h)
echo “js2zcode - decodes parchment game .js files”
echo “the .js file should start with ‘processBase64Zcode(’.”
echo “Usage:”
echo “-h Displays this help.”
echo “-d Use URL.”
echo “If none of these arguments are given, the only parameter is a local file name.”
echo “”
echo “Output file is always ‘game.blorb’.”
;;
d)
wget -O - -o /dev/null “echo $OPTARG” | sed “s/processBase64Zcode(’//g” | sed “s/=’)/=/g” | base64 --decode > game.blorb
echo “downloaded”
;;
?) ;;
esac
done

echo $1” is Probably a terrible way to implement this. Oh well.

if [ “$1” != “-h” ]; then
if [ “$1” != “-d” ]; then
if [ -z “$1” ]; then
echo “No arguments given.”
echo “js2zcode - decodes parchment game .js files”
echo “the .js file should start with ‘processBase64Zcode(’.”
echo “Usage:”
echo “-h Displays this help.”
echo “-d Use URL.”
echo “If none of these arguments are given, the only parameter is a local file name.”
echo “”
echo “Output file is always ‘game.blorb’.”
fi
if [ “$1” != “” ]; then
echo “-d argument not given; Using local file.”
cat “echo $1” | sed “s/processBase64Zcode(’//g” | sed “s/=’)/=/g” | base64 --decode > game.blorb
echo “Done! Try running game.blorb with your interpreter now.”
fi
fi
fi[/code]

To get the gamedata to feed to my shellscript as an argument, go to the page with your parchment game. View the page source (in firefox, it’s ctrl+u).
Some people put parchment in an iframe, so if you can’t find the string “lib/parchment.min.js” in the page source, look for an iframe and view the source for the page in the frame.

When you’ve found the right page, in the page source, look for a file named “parchment.transcript.settings.js”. View the source for THIS file.
In the settings file source, there should be a variable named ‘parchment.options.default_story’ (without quotes).
example:

parchment.options.default_story = "http://www.myexamplesite.tld/interpreter/game.gblorb.js"

In that example, you would copy the url “http://www.myexamplesite.tld/interpreter/game.gblorb.js” (without quotes).

now, save the shellscript in a text file and make it executable (chmod +x scriptname). run the shellscript like this:

./js2zcode -d http://www.myexamplesite.tld/interpreter/game.gblorb.js

In that example, ‘-d’ tells the script to look for a URL. if you just run ./js2zcode game.gblorb.js it will look for a locally saved file of the name ‘game.gblorb.js’.

The script invariably outputs to a file named ‘game.blorb’. It will overwrite if the file exists already. You can run the blorb with your interpreter of choice.

A few hints on making it work with windows:
You would have to re-write this in a batch script. If I still used windows regularly I would make one; If I do in the future, I will also post it here. But don’t count on it.
You can decode base64 (the encoding of the parchment .js games) with

certutil -decode encodedInputFileName decodedOutputFileName

Be aware that you will have to download the js file and remove the beginning processBase64Zcode(’ and the ending ') in the file first with a text editor.

I’m bring up this old topic, as I’m seriously stuck and don’t know why.

Wordsmith is distributed as a base64 .js for web interpreter, I am trying to decode the base64, but it always fails with ‘invalid input’ or corrupt file. link to zip file: interactivefables.itch.io/worldsmith and inside Worldsmith.gblorb.js

$ cp Worldsmith.gblorb.js toblorb.base64 --- edit file to strip prefix/postfix -- $ joe toblorb.base64 $ base64 -d toblorb.base64 > Wordsmith.gblorb $ gargoyle-free Wordsmith.gblorb

I tried the same thing last weekend with springthing.net/2017/stories … tright.zip and it’s gblorb.js - and am getting nowhere!

I’m on Linux and the joe editor seems to be ideal for working with large text files. I’m stripping the quotes and javascript, but my decode always fails. help!

Depending on how the site was generated, the .js file may look like either

processBase64Zcode('####');
$(document).ready(function() {
GiLoad.load_run(null, '####', 'base64');
});

(Where #### is the base-64-encoding game file.)

I tried decoding the leftright.gblorb.js on MacOS and had no trouble.

Thank you for the help. Ok, so the format error goes away if I strip the newline at the end. And it seems that gargoyle-free is error on both files, I tried Lectrote and it worked. So I’m good. Thanks again. Maybe we need to setup a website to do this automatically (page you can paste a URL) and download to browser.

i know this is offtopic, but how do you convert .gblorb to .glulx in the first place? i only know javascript, css, and html.

I’m not sure you really need to. I don’t believe I’ve ever seen a file with the extension .glulx - Glulx is a format, and one of the extensions for a glulx file is .gblorb.

A file with the extension .gblorb should run in a Glulx interpreter such as Gargoyle or Lectrote.

…unless I’ve misinterpreted your question.

There are files with the extension .ulx (for Glulx), but not very many of them. Mostly test files and games compiled with Inform 6.

You can extract .ulx from .gblorb using ifarchive.org/indexes/if-archive … blorb.html . However, there’s almost never any reason to do this. As far as I know, all interpreters that accept Glulx accept .gblorb.

i dont know how to use the python script.