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.