Inside the exe ↓

56 KB, ten scenes and one borrowed replayer

“Spiral staircase” is Kaleido's 64k intro for Woest 2002, where it came second. Conqui and mnemonix wrote the code and mnemonix the music; the exe was linked on 1 March 2002 at 12:41 UTC, during the party. Everything above was rebuilt from that exe: the music comes from the embedded XM through a port of the replayer, every texture from the exe's 13 texture scripts, and every mesh, camera and sync point from the disassembly. A video capture was used only to check the result.

Below the player you can follow the sync script against the music, read the unpacked image, take any frame apart into its draw calls next to the capture, step through the texture scripts, and switch two of the intro's own bugs on and off.

Packed exe
56,368 B
Unpacked image
240 KB
Song
76.8 s
Sync points
66

The show, end to end

The frame function (0x40106f) asks MiniFMOD for the order being heard and takes scene = order / 2. Every scene is therefore two patterns, 7.68 s, and every cut is a hard cut on a pattern boundary. At order 20 it calls exit(0). Click a scene to jump there.

    Before the first frame the exe builds its nine objects. After each one it clears the screen to a random dark cyan-ish colour, (0, rand()%127, rand()%127), and presents it: the nine-frame flicker at the start of the capture. Those 18 rand() calls are part of the stream the particle systems later draw from, so the reconstruction makes them too.

    The score

    All sync lives in one function, 0x40126e: a chain of if (order == O && row == R) tests with five setters. It is level-triggered, so a value is written again on every frame while its row plays (60 ms), and the decay starts after the row. The white line follows the player; click to jump.

    Hover the score.

    SetterObject fieldEffectDecay
    0x403277 flashobj38+1cadditive full-screen quad, texture 120 layer 1, grey flash·25530 per unit (13.6/s)
    0x403dfb punchobj30+18ring projection fovX = π/(3−p), fovY = π/(4−p); at 2 the rings collapse sideways25 per unit
    0x4043e2 selobj34+4, +8picks the crystal shape and kicks the camera 10° around Ykick: 10 per unit
    0x404ea6 shakeobj28+cadds shake·sin(20t) to the staircase look-at targetbuggy: one row long, see below
    0x4056f0 wobbleobj3c+4rotates the vase background by 5·w·cos(110·uptime) degrees1 per unit

    Time inside the parts is timeGetTime()/2200 since PlaySong, so one unit is 2.2 s and has nothing to do with the tempo. The song runs at speed 3, 125 BPM: a row is 0.06 s, a pattern 3.84 s. On the capture the picture is 0.214 s behind the start of the recording and stays there: all 35 cuts and flashes found by scene detection fall within one video frame of the predicted rows.

    Unpacking an obsolete UPX

    The exe is packed with UPX 0.71 (1999), which current UPX refuses: “packed with an obsolete version and cannot be unpacked”. Instead, tools/unupx.py maps the three sections into Unicorn, points the two imports the stub needs at fake functions, and runs the stub until it jumps into the unpacked code at 0x414524. LoadLibraryA and GetProcAddress return fake handles, so the stub's own import loop writes a recognisable value into every IAT slot, and the 91 imports fall out by name.

    The texture generator and the replayer were checked the same way: their agents ran the exe's own functions under Unicorn, with the C runtime and GDI stubbed, and compared the JavaScript ports against them, layer by layer and sample by sample.

    DLLImportsUsed for
    msvcr70.dll40maths, rand, new; the reason the zip carries the DLL (“don't start complaining…”)
    user32.dll20window, message loop, the loader's status bar
    gdi32.dll12drawing Arial text into a DIB for the two text textures
    kernel32.dll9resources (the texture scripts), the mixer thread
    winmm.dll8waveOut and timeGetTime
    d3d8.dll1Direct3DCreate8; the rest goes through COM vtables
    comctl32.dll1InitCommonControls for the status bar

    Where the bytes go

    The unpacked image is 0x3c000 bytes. Code is 88 KB; the song is the biggest single thing in it. Hover or tab through the map: the upper bar is the whole image, the strip below zooms into .text with one tick per function found by the disassembler, coloured by subsystem.

    Hover a region or a function.

    The rich header says Visual C++ 7.0 (build 9466). The 64 functions at 0x4148e5–0x416406 are the C runtime's static initialiser table at 0x419004: each builds one global matrix or material. Strings the loader never shows: “dit is gelukt denk ik” (“I think this worked”), “gore kut zooi”, “balbab”, “FMOD IS KAPOT” (the message box when the song fails to load) and the window title “Scene test”.

    A fixed-function engine with one draw call

    Every mesh in the intro goes through one dynamic vertex and index buffer of 25,000 entries (FVF 0x152: position, normal, colour, one UV). DrawIndexedPrimitive at 0x407bb4 is the only draw in the program. There are no render targets, no shaders, no gamma ramps and no post-processing: every glow, ray and flash is additive geometry over a black clear.

    A scene node carries seven state slots (fog, Z, cull, blend, lighting, material, and one that does nothing), and the device applies only what differs from the current state. Nodes use the world matrix Rz·Rx·Ry plus translation; cameras use T·Rx·Ry·Rz or a left-handed look-at, with a projection that takes two fields of view and no aspect ratio. The WebGL port keeps D3D's row vectors and 0..1 depth and has one shader for the fixed-function path: point lights with the vertex colour as material, linear range fog, texture × diffuse.

    PartBuilt fromAddress
    Logo rays5 metaballs, marching squares on 64×64 cells, each segment extruded toward the camera0x40b7db
    Ringsan open band of 40 triangles, 6 arms × 20 copies0x403cbc
    Staircase160 steps of 9°, 0.8 down each; four pillars; the same metaball curtain, hung vertically0x40454a
    Crystaltetrahedron or octahedron, 4 Sierpinski steps (the middle triangle dropped), a spike on every face0x4065af
    Vase4-lobed lathe, 32×30, pulsed and twisted every frame0x401e76
    Fountain3,600 sparks dropped by an emitter circling the vase0x402d63
    Tunnel11 additive 40×40 slices with the cloud texture0x40350c
    Finale2,000 cyan sparks pulled into a circling attractor, released and faded on contact0x402730

    Inside one frame

    A second copy of the intro and renderer, so the player above is left alone. Pick a moment: left is the reconstruction, right the nearest still from the capture, and below every draw call that frame makes, in order. The jump buttons are the moments with capture stills.

    –

    reconstruction, 640×480
    Capture still
    capture

    Stepping backwards replays the intro from the start, because the particle systems carry state from frame to frame. The vase and the vase background depend on the PC's uptime, so they only match the capture with the fitted value below.

    Thirteen texture scripts

    The 13 RT_RCDATA resources, 5,792 bytes in all, are programs for a small texture generator (0x40dd53, op table at 0x420bc8). Each works on four 256×256 layers with 28-byte records: an op, a source and destination layer and six parameters. The loader returns one layer, picked by the caller. Pick a script and a step to see the four layers after it; the layer the intro uploads is outlined. The noise ops call srand with their own seed, so they are repeatable; the ports match the exe's own code bit for bit, except text.

      Text (op 80) is drawn by GDI with Arial into a DIB and read back with GetPixel: “|KALEIDO|” at height 51, and “spiral”, “staircase”, “mnemonix”, “| conqui” for the end title. The browser draws it with its own Arial, so glyph edges differ. Resources 123 and 128 are never loaded: a glow with a wood swirl, and embossed cells.

      The tool they came from: a speculative node editor

      The exe only holds the compiled scripts: lists of ops that read and write four layers. The texture tool itself, probably node-based, is not in the exe, so this editor is a guess. To rebuild a graph, each op becomes a node, and its inputs are the nodes that last wrote the layers it reads. Copies (op 63) only move data between layers, so they disappear. Evaluating any of the 13 graphs gives the exe's layers byte for byte. The editor then compiles the graph back to 28-byte records over four layers, putting copies back where a value is still needed.

      Compiling also shows how much of each script the intro never uses. For the layer it loads, the KALEIDO logo (129) needs 14 of its 24 records and the crystal clouds (127) need 7 of 18. The rest compute other layers that are thrown away.

      Save and load

      In this browser

        As JSON

          Drag a node by its title. Drag from the dot on its right to an input on another node to connect them; drag a wire off an input to disconnect it. With the graph focused, Delete removes the selected node. Ctrl/⌘ Z undoes and Ctrl/⌘ Shift Z redoes. Graphs saved in this browser stay on this device; the JSON box moves them anywhere. Blue wires are the main input, brown ones the second input of a two-input op. Text uses the browser's Arial, as in the texture section above.

          The music: MiniFMOD, mirrored

          The replayer is not home-made: it is Firelight's MiniFMOD, linked in, playing a 31,399-byte FastTracker 2 module from memory at 0x419114. It outputs 44.1 kHz, 16-bit stereo through one looping 2-second waveOut buffer, refilled in 20 ms blocks by a time-critical thread that polls waveOutGetPosition.

          js/xmplayer.js ports it and renders the song before the intro starts, the way a 64k intro precalculates. Run against the exe's own mixer under an emulator, it matches sample for sample. What makes it sound unlike other XM players: linear interpolation on short 8-bit samples (the bright aliasing haze on the capture), 128-frame volume ramps on every note, and stereo mirrored relative to FastTracker 2.

          The demo asks for the order and row that are audible: MiniFMOD records them per 20 ms block and returns the block being played, so sync follows what you hear, up to 20 ms early.

          ModuleValue
          Channels, patterns, instruments10, 17, 15 (6 with samples)
          Tempospeed 6 in the header, F03 on every pattern: speed 3, 125 BPM
          Order list0 1 2 3 4 5 6 6 7 10 11 12 11 12 13 14 13 14 15 16 17 17
          Effects used0, 1, 2, 3, 8, A, F, R; no envelopes, no volume column
          Peakabout 21,800 of 32,767: it never clips
          Never heardorders 20–21: pattern 17 does not exist, and the exe has exited by then
          The rendered song, one band per order, pattern numbers below. Click to jump.

          Bugs you can switch on

          The text file says “we didn't feel like bug fixing anything at the moment”. Most of what follows is reproduced as is; three of them depend on the machine, and you can change the machine here. These controls change the player above and the frame inspector.

          Deviations and sources