intfiction.org

The Interactive Fiction Community Forum
It is currently Mon Nov 19, 2018 7:26 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sun Jun 01, 2014 2:46 pm 
Offline

Joined: Sun Jun 01, 2014 2:25 pm
Posts: 31
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 <url>   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 <url>   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

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 <url>   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 <url>   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


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:
Code:
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:
Code:
./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
Code:
./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
Code:
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.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Apr 15, 2017 12:20 pm 
Offline
User avatar

Joined: Fri Sep 30, 2016 7:02 pm
Posts: 406
Location: USA
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: https://interactivefables.itch.io/worldsmith and inside Worldsmith.gblorb.js

Code:
$ 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 http://www.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!

_________________
Thunderword not forgotten, will pick back up 2nd half of 2018.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Apr 15, 2017 12:47 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5804
Depending on how the site was generated, the .js file may look like either

Code:
processBase64Zcode('####');


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


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


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Apr 15, 2017 12:51 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5804
I tried decoding the leftright.gblorb.js on MacOS and had no trouble.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Apr 15, 2017 1:08 pm 
Offline
User avatar

Joined: Fri Sep 30, 2016 7:02 pm
Posts: 406
Location: USA
zarf wrote:
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.

_________________
Thunderword not forgotten, will pick back up 2nd half of 2018.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Jan 14, 2018 7:29 pm 
Offline

Joined: Sun Jan 14, 2018 7:20 pm
Posts: 2
i know this is offtopic, but how do you convert .gblorb to .glulx in the first place? i only know javascript, css, and html.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Jan 17, 2018 2:08 am 
Offline
User avatar

Joined: Tue Nov 08, 2011 8:11 am
Posts: 2757
Location: US - Central
Suvrenim wrote:
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.

_________________
http://hanonondricek.wixsite.com/pyramidif
https://pyramidif.itch.io/


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Jan 17, 2018 10:48 am 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5804
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 https://github.com/erkyrath/glk-dev/blo ... orbtool.py or the other tools at http://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.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Jan 17, 2018 12:21 pm 
Offline

Joined: Sun Jan 14, 2018 7:20 pm
Posts: 2
i dont know how to use the python script.


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group