paperlined.org
games > pc > Spelunky > cheating
document updated 15 years ago, on Feb 4, 2009
You can jump to normal levels easily via the debugger:
global.currLevel=12; room_goto(rTransition1);
However, most of the special levels require a little more work to jump to.

call tree

(the exact sequence/order aren't necessairily correct, and duplicate calls aren't listed)

level flags

flag description where normally set to cheat
global.blackMarket Black Market in scrLevelGen(), set iff global.genBlackMarket is set see genBlackMarket
global.genBlackMarket Black Market in oPlayer1.action(), in response to entering a oXMarket door global.currLevel=5; instance_create(oPlayer1.x-8,oPlayer1.y-8,oXMarket);
global.cityOfGold City of Gold in oPlayer1.action(), in response to entering a oXGold door global.currLevel=13; instance_create(oPlayer1.x-8,oPlayer1.y-8,oXGold);
global.lake rushing water level randomly, in oTransition.step() [lvl5-8] stopAllMusic(); global.currLevel=6; global.lake=1; room_goto(rLevel3);
global.darkLevel dark level randomly, in scrInitLevel() [lvl3-15] see below
global.snakePit "I hate snakes" randomly, in scrLevelGen() [lvl1-4] see below
global.cemetary "The dead are restless!" randomly, in scrInitLevel() [lvl5-8] see below
global.yetiLair "wet fur" randomly, in scrLevelGen() [lvl9-12] see below
global.alienCraft "psychic presence" randomly, in scrLevelGen() [lvl9-12] see below
global.sacrificePit "prayers to Kali" randomly, in scrLevelGen() [lvl13-15] see below
global.madeMoai Hedjet blue head in scrLevelGen(), randomly, but guaranteed to occur by lvl 12 global.currLevel=12; room_goto(rTransition1);

modifying flags that are randomly set from scrLevelGen()

To modify these, edit the .gmk, open 'scrLevelGen', and add this line just before the //shop comment:
execute_file("level_cheat.txt");
And then fill that file with contents like this (albeit modified as needed):
// ALWAYS set level flags when we can


    // ignore this: record some details for the bottom code
    tOrigSnakePit = global.snakePit;
    tOrigAlienCraft = global.alienCraft;
    tOrigSacrificePit = global.sacrificePit;



// ==== MODIFY THIS SECTION based on what cheats you want to do ====

if (global.levelType == 0)
{
    global.snakePit = true;
}


if (global.levelType == 2)
{
    // uncomment only one of these at a time, not both
    global.alienCraft = true;     // psychic presence
    //global.yetiLair = true;       // wet fur
}


if (global.levelType == 3)
{
    global.sacrificePit = true;
}




// ======== some of the changes made above require some objects to be placed ========
if (not tOrigSnakePit and global.snakePit)
{
    global.snakePit = false;    // we'll try to find any solution possible, but it may not be possible

    for (j = 0; j < 2; j += 1)
    {
        for (i = 0; i < 4; i += 1)
        {
            if (global.roomPath[i,j] == 0 and global.roomPath[i,j+1] == 0 and global.roomPath[i,j+2] == 0)
            {
                global.roomPath[i,j] = 7; // top of pit
                if (true)
                {
                    if (global.roomPath[i,j+2] == 0)
                    {
                        global.roomPath[i,j+1] = 8;
                        if (j == 0)
                        {
                            if (global.roomPath[i,j+3] == 0)
                            {
                                global.roomPath[i,j+2] = 8; // middle of pit
                                global.roomPath[i,j+3] = 9; // bottom of pit
                            }
                            else
                            {
                                global.roomPath[i,j+2] = 9;
                            }
                        }
                        else
                        {
                            global.roomPath[i,j+2] = 9;
                        }
                    }
                }
                else
                {
                    global.roomPath[i,j+1] = 9;
                }
                global.snakePit = true;
                i = 99;
                j = 99;
                break;
            }
        }
    }
}

if (not tOrigAlienCraft and global.alienCraft)
{
    k = rand(0,2);
    j = rand(1,2);
    for (i = k; i < 4; i += 1)
    {
        if (i == k) global.roomPath[i,j] = 7;
        else if (i == 3) global.roomPath[i,j] = 9;
        else global.roomPath[i,j] = 8;
    }
}

// this one doesn't seem to be working
if (not tOrigSacrificePit and global.sacrificePit)
{
    show_message("fark!");

    while (n == roomX)
    {
        n = rand(0,3);
    }
    
    for (i = 0; i < 4; i += 1)
    {
        if (i == 0) global.roomPath[n, i] = 7;
        else if (i == 3) global.roomPath[n, i] = 9;
        else global.roomPath[n, i] = 8;
    }
    oGame.idol = true;
    oGame.damsel = true;
}

Flags besides level feelings

Things to watchlist if you want to cheat a tiny bit, and see what special things have been generated on the current level.

abs(oPlayer1.x-oDamsel.x)+abs(oPlayer1.y-oDamsel.y) how far away the damsel is (or ERROR if she's not on this level at all)
abs(oPlayer1.x-oLockedChest.x)+abs(oPlayer1.y-oLockedChest.y) how far away the locked chest is (or ERROR if it's not on this level at all)
global.ashGrave whether the ASH grave has been created on this level