Category Archives: Software

Info Page – @FPAdventuresBot

@FPAdventuresBot currently posts images from the following games:

  • Myst (1993)
    • Extract tool: Riveal
    • Image count: 1531
    • Data files / areas covered:
      • INTRO.DAT
      • MYST.DAT
      • STONE.DAT
      • CHANNEL.DAT
      • SELEN.DAT
      • MECHAN.DAT
      • DUNNY.DAT
  • Lighthouse: The Dark Being (1996)
  • The 7th Guest (1993)
    • Extract tool: Custom
    • Image count: 482
    • Data files / areas covered:
      • AT, CH, DR, GA, HTBD, JHEK, LA, MB, MU, P, B, D, FH, HDISK, INTRO, K, LI, MC, N
  • The Journeyman Project (1993)
    • Extract tool: ffmpeg
    • Image count: 2045
    • Data files / areas covered:
      • CALDORIA/C1_NAV.AVI
      • CALDORIA/C4_NAV.AVI
      • CALDORIA/C5_NAV.AVI
      • FINALE/FINALE.AVI
      • MARS/MM_NAV.AVI
      • MARS/MU_NAV.AVI
      • NORAD/N_NAV.AVI
      • PREHIST/P_NAV.AVI
      • TSA/T_NAV.AVI
      • WSC/W_NAV.AVI
  • Return to Zork (1993)
    • Extract tool: Custom
    • Image count: 256
    • Data files / areas covered:
      • MS-DOS
      • Mac

Secret of Evermore (Bugfixed)

Secret of Evermore is a game for the Super Nintendo released in 1995. It continues to be a somewhat controversial title in the otherwise spotless Squaresoft SNES library… but I like it, and my wife plays it as a “comfort game” whenever she is feeling sick.

IPS is an antiquated binary patch file format, used to provide a “diff” of raw bytes that should be applied over an existing file. IPS patches for SNES games are widespread, and often do things like enable cheats, alter graphics, translate text, etc. In some cases, people have found bugs or glitches in the original code, and release an IPS patch to fix it. Often these are found from the work of speedrunners, who spot a glitch and exploit it to break the game in some way. The SNES hackers then identify the code problem behind the bug, and patch the raw binary code to close the hole. There’s a whole black art to crafting binary bugfixes – the space for a fix is severely limited, and if the new code is too big you have to find additional unused code area elsewhere to jump into (or optimize a different routine to make some free space!)

For some games, more than one bugfix patch is available. Managing these with the ubiquitous LunarIPS tool is a pain – you have to generate a bunch of intermediate ROMs, and the patches may conflict / overwrite one another without indication of the problem. There are better IPS patchers around, but I didn’t want to go on a research quest to find one. Besides, IPS is a pretty simple format – why not just write my own patcher?

I wanted a way to take a binary file, apply a complete “patch set” to it, and return the resulting bin. I wanted it to check for conflicts in patches, and give a descriptive message of which exact patches were colliding. And then I didn’t want to just serve up a cooked file, for copyright and maintainability reasons. “XYZ (Bugfixed)” hacks are too frequently outdated, as new patches are released. So I put a simple PHP frontend before it and a folder full of patches server-side.

The tool is here: https://greg-kennedy.com/SecretOfEvermore/

Users can upload a file. If the SHA-1 matches, it gets patched and they download the fixed version. This tool is for Secret of Evermore, with all the patches (i.e. “hard work”) done by Assassin17.

I may stand up sites for other games as I run across them, or merge these into a single “bugfixer” tool if it gets too out of control.

The patch.pl script follows.
Continue reading

Downloading from Soundcloud

A couple years ago, downloading a song from Soundcloud used to be pretty trivial. Their server would send you the complete 128kbps MP3, and then the local embedded control would allow you to seek at will. Because the file arrived in one large chunk, it was both easy to identify in cache, and easy to copy somewhere else to play back. Sometimes this still works… You’ll know by looking at the dev console, and see if it shows a huge MP3 file transfer. If so, you’re in luck! Copy it from the cache and you’re set.

Evidently they’ve changed this practice for other tunes, possibly to improve the latency of seeking at random in tracks, or possibly because they don’t want people getting music they shouldn’t be able to get. You can get Greasemonkey scripts which put the download button back, but these simply fire the URL off to an third-party site which “somehow” reconstructs the song and then sends it back your way. Very black-box magic stuff indeed.

However – If you can stream it, you can download it, as they say. Let’s take a look at how Soundcloud actually gets a song to you, and see if we can still figure out how to download something we may not really be allowed to.

Start the browser’s Developer Console and then browse to a song you want to hear. Keep an eye on the “network” activity, it will give you clues as to what is actually going on. As the song begins playing, you’ll see a lot of small network requests to magically named files:
mini_files

This seems promising. Download one or two and run “file” on it, and you get:
$ file *
c5f47vUnF3Ow.128.mp3?f10880d39085a94a0418a7e163b03d5226edfe2317e6aa1445547d76cf23a7ca5b08b0b9169eed2c0a13f681ab93c51d8e788dcaa887622ee2905d7463e4fd982e918b5b687caf75047026a3429731c5010a16: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, JntStereo
c5f47vUnF3Ow.128.mp3?f10880d39085a94a0418a7e167b03d5249919aaf544816306c9a5e3ca05a129454accfdda2750c51705ac2f68f036a37b2c482058312ab10625db87a6e3ab6dc1d1631dbd883a3f38786db484e66359daf667314eb8f03: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, JntStereo

Okay, so Soundcloud has broken the file into parts and is playing them back in sequence. You can pop one of these into your media player and listen to a portion of the song. We’re close, but how do we know where to find all these parts and put them together in order? Easy: there’s an m3u8 that has that for you – check the Dev Console again! Soundcloud’s player is using this to fetch the data in order from various URLs, and then stream it to you. For example, something like this:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:1.985272,
https://ec-hls-media.soundcloud.com/media/0/31762/c5f47vUnF3Ow.128.mp3?f10880d39085a94a0418a7e163b03d5226edfe2317e6aa1445547d76cf23a6c6277ac4a31c0a01842ddc2964536e126c07aa07555cce1108baa06b42a8a56548b485330689f4477467fbe84e3701184db02ae8
#EXTINF:2.977908,
https://ec-hls-media.soundcloud.com/media/31763/79410/c5f47vUnF3Ow.128.mp3?f10880d39085a94a0418a7e167b03d5249919aaf544816306c9a5e3ca05a13988480bef0d85fac22fe42482ceefe72b45f93798b344c894177b5503fecfe001728ea53a521df650649905f1f820170622633f8408d974a
#EXTINF:4.989302,
https://ec-hls-media.soundcloud.com/media/79411/159240//c5f47vUnF3Ow.128.mp3?f10880d39085a94a0418a7e168b03d52f1af9dc5c031765e833721190ff39af5838b01fab4994aa8e1cbf7325eac7c17bbc32c9af8a4f995094f28154eaf2285d51dae2371e29d5df21535551f28bc9d3d6cdf11c7f30fd3
#EXTINF:9.978604,
https://ec-hls-media.soundcloud.com/media/159241/318900/c5f47vUnF3Ow.128.mp3?f10880d39085a94a0418a7e169b03d52a8b3c33b59894223455854e2f950e750c62859d445307c2908ba5ad3f2b1c73b802a1616248b94bd6c5babf25058d658ad1566709910633c2cd63c67371fbb6692e6db87e986a283f0
...
#EXTINF:9.978604,
https://ec-hls-media.soundcloud.com/media/3352449/3512109/c5f47vUnF3Ow.128.mp3?f10880d39085a94a0418a7e061b03d52eb7d518bdc510e28891131df942c66df2d11c65c5f6f65b400607098a9a36cb891691d16355d126d2ecbc6451bb48f82561d15b81d006b4104caff07fffa8361c42652b9341faefa8f4513
#EXTINF:5.642352,
https://ec-hls-media.soundcloud.com/media/3512110/3602388/c5f47vUnF3Ow.128.mp3?f10880d39085a94a0418a7e061b03d52eb7d518bdc510e28891131df942c66df2d11c65c5f6f65b400607098a9a36cb891691d16355d126d28cfc6401ebd8f8214c9a4dd73e90391e79897cc892a72bcd4883580fdef67b3cf0e33
#EXT-X-ENDLIST

An interesting aside, it seems these URLs time out after a short period of time, leading to 403 Forbidden errors if you try to access it again. No doubt these huge URL parameters point to some browser session or timestamp which becomes invalid after a while. If that happens, reload the page and start playing again to generate new files.

So to recap all this: we need to

  • take the m3u8 file,
  • retrieve each mp3 segment,
  • and concatenate them together.

Getting the m3u8 programmatically is hard, so just copy it from the browser : ) And to put these together you’ll need mp3cat installed – see http://tomclegg.ca/mp3cat for info.

#!/usr/bin/env perl
open(FP,"playlist.m3u8") or die "can't open playlist: $!";

my $piece = 0;
while( < FP > )
{
chomp;
next if ($_ =~ m/^#/);
$filename = sprintf('outdir/%02s.mp3',$piece);
print `wget --no-check-certificate -O $filename $_`;
$piece++;
}

print `cat outdir/*.mp3 | mp3cat - - > output.mp3`;

Arduino Raytracer

Every programmer worth his salt has written a raytracer of some sort. It’s one of the classic “recursion exercises”, with a fair amount of math to wrap your head around. I’m not interested in writing one to run on the PC – there are already far more capable ones that can run on pretty much any hardware, complete with optimizations and features I couldn’t hope to implement in my lifetime.

Instead, I decided to write a raytracer which targets the Atmega 328 microcontroller in my Arduino! In the end, I succeeded in banging one together that calculates ray-triangle intersection, and each triangle can have a material attached with ambient / diffuse / transparent / reflective values and an RGB color. The scene is compiled in with a .h file (stored in PROGMEM), and outputs a PPM image pixel-by-pixel over the serial port.

The same engine can be used on the PC with a few modifications, so I was able to benchmark the performance of the Arduino in comparison with a modern laptop. The “detailed scene” rendered a 640×640 image in 263 seconds on the laptop. The same scene, scaled to only 64×64, still took 4008.471 seconds… in other words, the PC outperformed the Arduino by a factor of ~1500.

I posted the code, and further write-up, on the Arduino.cc message board at this link: http://forum.arduino.cc/index.php?topic=281076.0. There are a lot of features that COULD be added here, but none that I actually intend to do. If I need a raytracer in the future, I’m just downloading POVRay : )

Crazy Taxi Garmin GPS Voice

Here is a project I’d been talking about for years, but never actually pulled it off until recently. It’s a voice set for a Garmin GPS, which replaces the default “narrator” with the obnoxious announcer from Crazy Taxi.
All voice clips were pulled from the PC version of the game, which had them in convenient .wav format already. Some trim / normalize with Audacity and import into Garmin Voice Studio to assemble together. I wanted to do more than just the announcer, but didn’t have any luck with that… there just weren’t enough clips to make it happen.

Here’s a video of the system in action:

I hosted all the downloadables on archive.org. You can get it from here:
https://archive.org/details/Garmin-CrazyTaxiVoice

GregerQuest

gqTitle
Before there was World of Warcraft, there was Everquest. I never played it but I had a buddy in college who did: he talked about how amazing the MMO genre was, with all its social aspects, technical quirks, and just plain cool experiences.

Naturally it inspired me to make my own clone. In Visual Basic. With 2d graphics and piping everything through the Winsock .ocx control. Full of programmer art made with a pirated copy of Bryce 3d.

gqChars

Ah, the wide-eyed days of a young programmer in a rapidly expanding genre. It’s like I was playing out every cliche of the Gamedev.net newbie at once. The one thing I had going for me, though, was a thorough understanding of the impossibility of such a project – and a sense of humor about it all. For example, I often joked that the only enemies were going to be Gelatinous Cubes, because that would be easy to render. I once wrapped a photo of my roommate’s face on a sphere to use for a hideous player character head. And so on. Eventually I got about as far as a character select screen, with a couple songs, before giving up and moving on to something else.

Unlike SlugFest, this is one that isn’t ever going to get off the ground. If anyone is interested in the art and music resources, you can have them: hereby released into the Public Domain.

shore

This isn’t my only brush with the MMO genre. Later on some friends and I tried another take on it (“Draconis”) as the U of A Game Dev club project – with a result somewhat similar to The Mana World, and it once held up to five players online simultaneously. The real killer for these kind of games is the sheer amount of content required. Though Draconis worked technically, all the content in the world was viewable at first login. Hardly a compelling MMO experience.

Download GregerQuest Resources: .ZIP file, 1.9mb.

Smoke Help (for OSX)

This is a tool to help people quit smoking. My wife gave me the idea, I just wrote it.

coach

Start the program up and put it into Learn Mode. Every time you have a cigarette, hit the “SMOKE” button. This trains the program, over the course of 100 cigarettes, your (natural) average time between cigarettes.

Then put it into Coach Mode. At this point the program will begin telling you when it’s time to smoke again, using an alarm. Don’t smoke until instructed to do so, and then hit the button when you do. The program starts by alarming at the learned rate, but extends the interval each cigarette. Eventually your rate will slow down to the point where quitting is natural.

At least, in theory. My wife quit without my help so I wasn’t ever able to test it.

This is the sort of thing that would be super-ideal as a mobile app. I don’t have time nor inclination to set that up, but I’d love to see it. So, this is now public domain software. (Included font isn’t though).

Smoke Help OSX Binary – .zip – 2.45 MB
Smoke Help source code – .tar.gz – 227kb

Minus Infection

I took a programming languages class in college, which used Scheme to demonstrate concepts like lexers, parsers, etc. The final project was to write our own interpreted object-oriented language. I enjoyed the class but never quite got the hang of Scheme. So when the time came to write the language, I did the minimum possible in Scheme, and implemented the rest as a standard library add-on to my own language.

Cutting things to the bare minimum resulted in a language with only seven constructs, and the only arithmetic operation was subtraction. Addition would thus be implemented as minus (a, minus(0, b)). IF statements were simply WHILE loops that ran zero or one times. And so on.

Sadly, I don’t have the source code any more. But I do have the README file.

Minus Infection
A Programming Language by
Greg Kennedy

I. Introduction
What is Minus Infection? MI is a programming language which aims to be Turing complete and support object-oriented programming with as few primitives as possible. It is written in Scheme. Functionality is provided by external Library files, which define many of the functions you would otherwise miss from your favorite language.
Because of this, the actual implementation of MI is rather simple, but powerful enough that you can use the built-in functions to build vastly more complicated ones.

But why? Scheme is a fine language. It is really quite powerful. But I just can’t get the hang of all those parentheses and cars and cdrs. So I thought I’d minimize the work I had to do in Scheme, and instead move that work into MI. It’s also sort of an experiment for me to discover just how little is really needed to make a usable language.

II. How do I use it?
MI source files are simply text files – create them in Notepad or vi or whatever.
Your source file is the main routine of your program.

III. What are the primitives?
MI recognizes as “true” any expression which evaluates to less than 0, and “false” as any expression which evaluates to “equal to or greater than 0” (i.e. “not false).

The only variable type MI understands is integer arrays. You can create single variables in your source and omit the subscript when later referencing them – the parser will simply fill in the missing subscript with a [0].

See section 4 for methods for dealing with strings. Internally they are represented (like in C) as an array of integers representing character codes.

Arrays maintain their own sizes and will warn of an out-of-bounds access. For strings, no special termination character is needed.

These primitives are built-in to MI:
MINUS (X, Y) – perform the calculation X – Y and return the result.
LTZ (X) – returns -1 if X is less than 0, 0 otherwise.
WHILE (COND, BLOCK) – continually executes BLOCK as long as COND is true.
SET (X, EXP) – sets X to the evaluated result of expression EXP.
DEFINE (NAME, PLIST, BLOCK) – sets
INT (NAME, SIZE) – declares an array named NAME of length SIZE
DOT (NAME, MEMBER) – OO operator: call member function or access member variable
PRINT (x) – Prints X to the screen. X is a string.

IV. What is in the libraries?
You’ve no doubt noticed that the language seems a little sparse. That’s because all the real functionality comes from the libraries.
To load a library, simply place this command in your source file:
LIB “FILENAME” – when parsing, this line causes the execution of FILENAME.

The standard library is called default.lib. It provides the following functions:
< (X, Y), > (X, Y), = (X, Y),
<= (X,Y), >= (X, Y) – Conditionals returning true if X (op) Y.
IF (COND, BLOCK1, BLOCK2) – if COND is TRUE, executes BLOCK1; else executes BLOCK2
– (X, Y) – behaves like MINUS
+ (X, Y) – calculates X + Y, returns result
*, /, % (X,Y) – multiply, divide, modulus
NAND(X,Y), NOR(X,Y), NOT(X),
AND(X,Y), OR(X,Y), XOR(X,Y) – boolean operations.
FOR(X, COND, INC, BLOCK) – Similar to C for loops
STRCPY (X, Y) – copies string Y over string X.

V. Example code?
This program prints “Hello, World!” to the screen.

LIB "default.lib"
VAR (HWORLD, 14);
STRCPY(HWORLD,"Hello, World!");
PRINT(HWORLD);

0dbfs.pl: Bringing a Nuke to the Loudness War

Ever heard of the Loudness War? It’s the steady ramp-up in perceived volume that has plagued popular music for the past 30+ years. Producers have steadily chipped away at dynamic range in an effort to make a hotter track. Audio signal-to-noise ratio suffers. Nowadays the typical radio song has a 3-6 dB dynamic range (for comparison, CDs have a theoretical 96 dB range).

Well folks: I’m playing to WIN. Here is a compressor that scales ALL of your peaks to 100%: in other words, compression at a ratio of INFINITY : 1… or a dynamic range of 0. TAKE THAT, PRODUCERS.

Here’s an example in action, cutting from Clair de Lune. First, the original. Then, the RADIO-READY version.

Doesn’t this just sound so much more… hip / edgy / loud / etc?

Interestingly, I tried it on a selection of pop music. It makes for a great demonstration of “listener fatigue”.

0dbfs.zip – zip file containing Perl script, 1.7 kB

cfg_parse – Simple Config File Parser in C

There is no standard way in C to parse config files. Several libraries have sprung up to solve the problem, but perhaps that is overkill for what should be a simple operation.

Presenting: cfg_parse – a compile-in solution for reading key-value pairs from file(s), looking up settings, and writing a config file back to disk. I could write more about it, but the included main.c shows all the functionality.

// driver test program for cfg_parse

#include "cfg_parse.h"

#include

int main(int argc, char **argv)
{
// Pointer to a cfg_struct structure
struct cfg_struct *cfg;

// Initialize config struct
cfg = cfg_init();

// Specifying some defaults
cfg_set(cfg,"KEY","VALUE");
cfg_set(cfg,"KEY_A","DEFAULT_VALUE_A");

// "Required" file
if (cfg_load(cfg,"config.ini") < 0)
{
fprintf(stderr,"Unable to load cfg.ini\n");
return -1;
}

// Several "optional" files can be added as well
//  Each subsequent call upserts values already in
//  the cfg structure.
cfg_load(cfg,"/usr/local/etc/config.ini");
cfg_load(cfg,"~/.config");

// Retrieve the value for key INFINITY, and print
printf("INFINITY = %s\n",cfg_get(cfg,"INFINITY"));

// Retrieve the value for key "KEY", and print
printf("KEY = %s\n",cfg_get(cfg,"KEY"));

// Delete the key-value pair for "DELETE_ME"
cfg_delete(cfg,"DELETE_ME");

// Dump cfg-struct to disk.
cfg_save(cfg,"config_new.ini");

// All done, clean up.
cfg_free(cfg);

return 0;
}

Download: cfg_parse.1.0.tar (version 1.0, 4kb .tar.gz)