Path: blob/master/Sonic 2/Scripts/LevelSelect/MenuControl.txt
1478 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Menu Control Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.timer12private alias object.value1 : object.scrollDelayUp13private alias object.value2 : object.scrollDelayDown14private alias object.value3 : object.currentSelection15private alias object.value4 : object.soundTestCooldown1617// HexNo Aliases18private alias object.value0 : hexNo.number19private alias object.value1 : hexNo.highlighted2021private alias 0 : HEXNO_HIGHLIGHT_FALSE22private alias 16 : HEXNO_HIGHLIGHT_TRUE2324private alias 0 : MENUCONTROL_INIT25private alias 1 : MENUCONTROL_FADEIN26private alias 2 : MENUCONTROL_MAIN27private alias 3 : MENUCONTROL_LOADLEVEL28private alias 4 : MENUCONTROL_LOADSPECIAL2930// The maximum number of selections available31// (Inclusive limit)32private alias 22 : MAX_SELECTION_COUNT3334// Music Loops35private alias 152750 : MUSIC_LOOP_EHZ_1P36private alias 18671 : MUSIC_LOOP_MCZ_2P // This is 18672 in some other cases...37private alias 293572 : MUSIC_LOOP_OOZ38private alias 309378 : MUSIC_LOOP_MPZ39private alias 1 : MUSIC_LOOP_HTZ40private alias 1 : MUSIC_LOOP_ARZ41private alias 95868 : MUSIC_LOOP_CNZ_2P42private alias 62820 : MUSIC_LOOP_CNZ_1P43private alias 1 : MUSIC_LOOP_DEZ44private alias 99356 : MUSIC_LOOP_MCZ_1P45private alias 99572 : MUSIC_LOOP_EHZ_2P46private alias 198253 : MUSIC_LOOP_SCZ47private alias 684580 : MUSIC_LOOP_CPZ48private alias 99874 : MUSIC_LOOP_WFZ49private alias 59852 : MUSIC_LOOP_PPZ50private alias 496644 : MUSIC_LOOP_SPECIAL51private alias 38679 : MUSIC_LOOP_INV5253// Music Event Aliases54private alias 2 : MUSICEVENT_TRANSITION555657// ========================58// Function Declarations59// ========================6061reserve function MenuControl_HandleSecrets62reserve function MenuControl_SoundTestPlayer636465// ========================66// Static Values67// ========================6869public value MenuControl_optionsMenuOpen = 070private value MenuControl_optionsMenuCounter = 071private value MenuControl_debugModeCounter = 072private value MenuControl_emeraldCodeCounter = 073private value MenuControl_continueCodeCounter = 074private value MenuControl_PPZCodeCounter = 0757677// ========================78// Tables79// ========================8081// Code to open the game config menu82private table MenuControl_OptionsMenu830, 0, 084end table8586// Code to enable debug mode87private table MenuControl_SecretDebugMode881, 9, 9, 2, 1, 1, 2, 489end table9091// Code to give all emeralds92private table MenuControl_SecretEmeralds934, 1, 2, 694end table9596// Code to give 14 continues97private table MenuControl_SecretContinues981, 1, 2, 499end table100101// Code to replace Hidden Palace Zone with Proto Palace Zone102private table MenuControl_SecretPPZ1033, 3, 3, 11, 16, 16, 16, 4104end table105106107// This table holds data for every stage with six values for every stage,108// -> First entry is menu table the stage option is on109// -> Second is what number this one is on the list, from top to bottom110// -> Third is the active stage list the stage is on111// -> Fourth is the stage's position in the stage list112// -> Fifth is the menu entry of what is on the opposite side of this selection, like how MTZ is to the right of EHZ and vice versa113// -> Sixth is the icon the entry uses114115private table MenuControl_EntryTable1160, 0, 1, 0, 14, 1 // 0 - Emerald Hill 11170, 1, 1, 1, 15, 1 // 1 - Emerald Hill 21180, 3, 1, 2, 17, 2 // 2 - Chemical Plant 11190, 4, 1, 3, 17, 2 // 3 - Chemical Plant 21200, 6, 1, 4, 18, 3 // 4 - Aquatic Ruin 11210, 7, 1, 5, 18, 3 // 5 - Aquatic Ruin 21220, 9, 1, 6, 19, 4 // 6 - Casino Night 11230, 10, 1, 7, 19, 4 // 7 - Casino Night 21240, 12, 1, 8, 20, 5 // 8 - Hill Top 11250, 13, 1, 9, 20, 5 // 9 - Hill Top 21260, 15, 1, 10, 21, 6 // 10 - Mystic Cave 11270, 16, 1, 11, 21, 6 // 11 - Mystic Cave 21280, 18, 1, 12, 22, 8 // 12 - Oil Ocean 11290, 19, 1, 13, 22, 8 // 13 - Oil Ocean 21301, 0, 1, 14, 0, 9 // 14 - Metropolis 11311, 1, 1, 15, 1, 9 // 15 - Metropolis 21321, 2, 1, 16, 2, 9 // 16 - Metropolis 31331, 3, 1, 17, 2, 10 // 17 - Sky Chase1341, 6, 1, 18, 4, 11 // 18 - Wing Fortress1351, 9, 1, 19, 6, 12 // 19 - Death Egg1361, 12, 1, 20, 8, 7 // 20 - Hidden Palace (or Proto Palace)1371, 15, 2, 0, 10, 13 // 21 - Special Stage1381, 18, 0, 0, 67, 0 // 22 - Sound Test139end table140141142// ========================143// Function Defintions144// ========================145146private function MenuControl_HandleSecrets147// Set the Special Stage act number, for acts 1-8148if hexNo[+1].number < 8149SetTableValue(hexNo[+1].number, 129, MenuControl_EntryTable)150end if151152// Handle the options menu check153GetTableValue(temp0, MenuControl_optionsMenuCounter, MenuControl_OptionsMenu)154155if temp0 == hexNo[+1].number156MenuControl_optionsMenuCounter++157if MenuControl_optionsMenuCounter == 3158MenuControl_optionsMenuCounter = 0159160CreateTempObject(TypeName[Config Screen], 0, 0, 0)161MenuControl_optionsMenuOpen = true162163PlaySfx(SfxName[Resume], false)164end if165else166MenuControl_optionsMenuCounter = 0167end if168169// Handle the debug mode code170GetTableValue(temp0, MenuControl_debugModeCounter, MenuControl_SecretDebugMode)171172if temp0 == hexNo[+1].number173MenuControl_debugModeCounter++174if MenuControl_debugModeCounter == 8175MenuControl_debugModeCounter = 0176177stage.debugMode = true178179PlaySfx(SfxName[Ring L], false)180end if181else182MenuControl_debugModeCounter = 0183end if184185// Handles the code for all emeralds186GetTableValue(temp0, MenuControl_emeraldCodeCounter, MenuControl_SecretEmeralds)187188if temp0 == hexNo[+1].number189MenuControl_emeraldCodeCounter++190if MenuControl_emeraldCodeCounter == 4191MenuControl_emeraldCodeCounter = 0192193// Give the player all 7 emeralds194specialStage.emeralds = 0x7F195#platform: USE_ORIGINS196game.cheatEmeralds = true197#endplatform198PlaySfx(SfxName[Emerald], false)199StopMusic()200end if201else202MenuControl_emeraldCodeCounter = 0203end if204205if MenuControl_debugModeCounter < 2206GetTableValue(temp0, MenuControl_continueCodeCounter, MenuControl_SecretContinues)207if temp0 == hexNo[+1].number208MenuControl_continueCodeCounter++209if MenuControl_continueCodeCounter == 4210MenuControl_continueCodeCounter = 0211212player.continues = 14213PlaySfx(SfxName[Continue], false)214end if215else216MenuControl_continueCodeCounter = 0217end if218else219MenuControl_continueCodeCounter = 0220end if221222#platform: USE_ORIGINS223// In place of unlocking PPZ, Origins added in some cool debug stuff instead224CallNativeFunction4(NotifyCallback, NOTIFY_DEBUGPRINT, stage.debugMode, MenuControl_PPZCodeCounter, hexNo[+1].number)225#endplatform226227if stage.debugMode == true228GetTableValue(temp0, MenuControl_PPZCodeCounter, MenuControl_SecretPPZ)229if temp0 == hexNo[+1].number230MenuControl_PPZCodeCounter++231if MenuControl_PPZCodeCounter == 8232MenuControl_PPZCodeCounter = 0233234#platform: USE_STANDALONE235// Change the Hidden Palace slot to use Proto Palace instead236SetTableValue(BONUS_STAGE, 122, MenuControl_EntryTable)237SetTableValue(11, 123, MenuControl_EntryTable)238#endplatform239240PlaySfx(SfxName[Ring L], false)241242// Set the Hidden Palace unlock flag to true243saveRAM[46] = true244end if245else246MenuControl_PPZCodeCounter = 0247end if248end if249end function250251252private function MenuControl_SoundTestPlayer253// Don't play songs in quick succession254if object.soundTestCooldown == 0255object.soundTestCooldown = 30256257switch hexNo[+1].number258case 0259break260261case 1262SetMusicTrack("Results.ogg", 0, true)263PlayMusic(0)264break265266case 2267SetMusicTrack("EmeraldHill.ogg", 0, MUSIC_LOOP_EHZ_1P)268PlayMusic(0)269break270271case 3272SetMusicTrack("MysticCave2.ogg", 0, MUSIC_LOOP_MCZ_2P)273PlayMusic(0)274break275276case 4277SetMusicTrack("OilOcean.ogg", 0, MUSIC_LOOP_OOZ)278PlayMusic(0)279break280281case 5282SetMusicTrack("Metropolis.ogg", 0, MUSIC_LOOP_MPZ)283PlayMusic(0)284break285286case 6287SetMusicTrack("HillTop.ogg", 0, MUSIC_LOOP_HTZ)288PlayMusic(0)289break290291case 7292SetMusicTrack("AquaticRuin.ogg", 0, MUSIC_LOOP_ARZ)293PlayMusic(0)294break295296case 8297SetMusicTrack("CasinoNight2.ogg", 0, MUSIC_LOOP_CNZ_2P)298PlayMusic(0)299break300301case 9302SetMusicTrack("CasinoNight.ogg", 0, MUSIC_LOOP_CNZ_1P)303PlayMusic(0)304break305306case 10307SetMusicTrack("DeathEgg.ogg", 0, MUSIC_LOOP_DEZ)308PlayMusic(0)309break310311case 11312SetMusicTrack("MysticCave.ogg", 0, MUSIC_LOOP_MCZ_1P)313PlayMusic(0)314break315316case 12317SetMusicTrack("EmeraldHill2.ogg", 0, MUSIC_LOOP_EHZ_2P)318PlayMusic(0)319break320321case 13322SetMusicTrack("SkyChase.ogg", 0, MUSIC_LOOP_SCZ)323PlayMusic(0)324break325326case 14327SetMusicTrack("ChemicalPlant.ogg", 0, MUSIC_LOOP_CPZ)328PlayMusic(0)329break330331case 15332SetMusicTrack("WingFortress.ogg", 0, MUSIC_LOOP_WFZ)333PlayMusic(0)334break335336case 16337SetMusicTrack("Extra.ogg", 0, MUSIC_LOOP_PPZ)338PlayMusic(0)339break340341case 17342SetMusicTrack("Options.ogg", 0, true)343PlayMusic(0)344break345346case 18347SetMusicTrack("SpecialStage.ogg", 0, MUSIC_LOOP_SPECIAL)348PlayMusic(0)349break350351case 19352SetMusicTrack("Boss.ogg", 0, true)353PlayMusic(0)354break355356case 20357SetMusicTrack("FinalBoss.ogg", 0, true)358PlayMusic(0)359break360361case 21362SetMusicTrack("Ending.ogg", 0, false)363PlayMusic(0)364break365366case 22367SetMusicTrack("Super.ogg", 0, true)368PlayMusic(0)369break370371case 23372SetMusicTrack("Invincibility.ogg", 0, MUSIC_LOOP_INV)373PlayMusic(0)374break375376case 24377PlaySfx(SfxName[Life], false)378PauseMusic()379ResetObjectEntity(26, TypeName[Music Event], MUSICEVENT_TRANSITION, 0, 0)380object[26].priority = PRIORITY_ACTIVE381break382383case 25384SetMusicTrack("TitleScreen.ogg", 0, false)385PlayMusic(0)386break387388case 26389SetMusicTrack("ActComplete.ogg", 0, false)390PlayMusic(0)391break392393case 27394SetMusicTrack("GameOver.ogg", 0, false)395PlayMusic(0)396break397398case 28399SetMusicTrack("Continue.ogg", 0, false)400PlayMusic(0)401break402403case 29404StopMusic()405PlaySfx(SfxName[Emerald], false)406break407408case 30409SetMusicTrack("Credits.ogg", 0, false)410PlayMusic(0)411break412413case 31414SetMusicTrack("Drowning.ogg", 0, false)415PlayMusic(0)416break417end switch418end if419end function420421422// ========================423// Events424// ========================425426event ObjectUpdate427// Setup the HexNo object428object[+1].xpos = screen.xcenter429object[+1].xpos += 118430431switch object.state432case MENUCONTROL_INIT433object.timer = 320434SetScreenFade(0, 0, 0, object.timer)435object[+1].ypos = 160436object[+1].priority = PRIORITY_ACTIVE437object.state++438break439440case MENUCONTROL_FADEIN441if object.timer > 0442object.timer -= 16443else444PlayMusic(0)445object.state++446end if447SetScreenFade(0, 0, 0, object.timer)448break449450case MENUCONTROL_MAIN451// Don't do any of this if the options menu is open452if MenuControl_optionsMenuOpen == false453if keyDown[0].down == true454object.scrollDelayUp = 0455object.scrollDelayDown++456if object.scrollDelayDown == 1457object.currentSelection++458end if459460object.scrollDelayDown %= 12461else462if keyDown[0].up == true463object.scrollDelayDown = 0464object.scrollDelayUp++465if object.scrollDelayUp == 1466object.currentSelection--467end if468469object.scrollDelayUp %= 12470else471object.scrollDelayUp = 0472object.scrollDelayDown = 0473end if474end if475476if object.currentSelection > MAX_SELECTION_COUNT477object.currentSelection = 0478end if479480if object.currentSelection < 0481object.currentSelection = MAX_SELECTION_COUNT482end if483484temp0 = object.currentSelection485temp0 *= 6486temp0++487GetTableValue(temp2, temp0, MenuControl_EntryTable)488temp0 += 3489GetTableValue(temp1, temp0, MenuControl_EntryTable)490491switch temp1492default493checkResult = keyPress[0].left494checkResult |= keyPress[0].right495496if checkResult == true497object.currentSelection = temp1498end if499500hexNo[+1].highlighted = HEXNO_HIGHLIGHT_FALSE501502if keyPress[0].buttonA == true503keyPress[0].start = true504end if505break506507case 67 // Sound test508if object.soundTestCooldown > 0509object.soundTestCooldown--510end if511512hexNo[+1].highlighted = HEXNO_HIGHLIGHT_TRUE513514#platform: USE_STANDALONE515if keyPress[0].buttonA == true516#endplatform517#platform: USE_ORIGINS518if keyPress[0].buttonC == true519#endplatform520hexNo[+1].number += 16521end if522523if keyPress[0].left == true524hexNo[+1].number--525end if526527if keyPress[0].right == true528hexNo[+1].number++529end if530531// Limit the number's maximum count532hexNo[+1].number &= 31533534if keyPress[0].buttonB == true535CallFunction(MenuControl_SoundTestPlayer)536CallFunction(MenuControl_HandleSecrets)537end if538539#platform: USE_STANDALONE540if keyPress[0].buttonC == true541#endplatform542#platform: USE_ORIGINS543if keyPress[0].buttonA == true544#endplatform545CallFunction(MenuControl_SoundTestPlayer)546CallFunction(MenuControl_HandleSecrets)547end if548break549end switch550551temp0 = object.currentSelection552temp0 *= 6553GetTableValue(temp1, temp0, MenuControl_EntryTable)554temp0++555556if temp1 == MENU_1557menu2.selection = -1558GetTableValue(menu1.selection, temp0, MenuControl_EntryTable)559else // MENU_2560menu1.selection = -1561GetTableValue(menu2.selection, temp0, MenuControl_EntryTable)562end if563564// Set the preview image to what it should be565temp0 += 4566GetTableValue(BGAnimation_currentPreview, temp0, MenuControl_EntryTable)567568// Player selected the option?569if keyPress[0].start == true570571// Special Stage572if object.currentSelection == 21573PlaySfx(SfxName[Warp], false)574object.state = MENUCONTROL_LOADSPECIAL575fadeColor = 208576fadeColor <<= 16577temp0 = 255578temp0 <<= 8579fadeColor += temp0580fadeColor += 224581else582// Hidden Palace?583if object.currentSelection == 20584// See if the player has it unlocked585if saveRAM[46] == true586// Proceed and load the level like normal587object.state = MENUCONTROL_LOADLEVEL588else589// Haven't played it legitimately yet, sorry...590PlaySfx(SfxName[Fail], false)591end if592else593// Normal stage - let the player proceed594object.state = MENUCONTROL_LOADLEVEL595end if596end if597end if598end if599break600601case MENUCONTROL_LOADLEVEL602if object.timer < 256603music.volume -= 10604object.timer += 16605SetScreenFade(0, 0, 0, object.timer)606else607#platform: USE_ORIGINS608CallNativeFunction2(NotifyCallback, NOTIFY_LEVEL_SELECT_MENU, true)609CallNativeFunction4(NotifyCallback, NOTIFY_PLAYER_SET, stage.playerListPos, stage.player2Enabled, 0)610#endplatform611612StopMusic()613temp0 = object.currentSelection614temp0 *= 6615temp0 += 2616GetTableValue(temp1, temp0, MenuControl_EntryTable)617temp0++618GetTableValue(temp2, temp0, MenuControl_EntryTable)619stage.activeList = temp1620stage.listPos = temp2621LoadStage()622SetScreenFade(0x00, 0x00, 0x00, 0xFF)623end if624break625626case MENUCONTROL_LOADSPECIAL627if object.timer < 768628music.volume -= 10629object.timer += 8630SetScreenFade(0xD0, 0xFF, 0xE0, object.timer)631else632StopMusic()633temp0 = object.currentSelection634temp0 *= 6635temp0 += 2636GetTableValue(temp1, temp0, MenuControl_EntryTable)637temp0++638GetTableValue(temp2, temp0, MenuControl_EntryTable)639stage.activeList = temp1640stage.listPos = temp2641LoadStage()642SetScreenFade(0xD0, 0xFF, 0xE0, 0xFF)643end if644break645end switch646end event647648649event ObjectDraw650// Two rows, two menus to be drawn651652temp0 = screen.xcenter653temp0 -= 10654DrawMenu(MENU_1, temp0, 16)655656temp0 = screen.xcenter657temp0 += 142658DrawMenu(MENU_2, temp0, 16)659end event660661662event ObjectStartup663// Load the sprite sheet664// No need to setup sprite frames since using the menu system will handle them automatically665LoadSpriteSheet("LevelSelect/Text.gif")666667// All Menu Control objects should be active668// -> Note that there should only ever be one of them in a scene, though669foreach (TypeName[Menu Control], arrayPos0, ALL_ENTITIES)670object[arrayPos0].priority = PRIORITY_ACTIVE671next672673#platform: USE_STANDALONE674if stage.actNum < 3675options.stageSelectFlag = true676end if677#endplatform678679options.touchControls = false680681SetMusicTrack("Options.ogg", 0, true)682683// Setup menu 1 (left column)684SetupMenu(MENU_1, 0, 3, 1)685686// Add the entries687AddMenuEntry(MENU_1, "EMERALD HILL@@ 1", true)688AddMenuEntry(MENU_1, "2", false)689AddMenuEntry(MENU_1, " ", false)690AddMenuEntry(MENU_1, "CHEMICAL PLANT 1", true)691AddMenuEntry(MENU_1, "2", false)692AddMenuEntry(MENU_1, " ", false)693AddMenuEntry(MENU_1, "AQUATIC RUIN@@ 1", true)694AddMenuEntry(MENU_1, "2", false)695AddMenuEntry(MENU_1, " ", false)696AddMenuEntry(MENU_1, "CASINO NIGHT@@ 1", true)697AddMenuEntry(MENU_1, "2", false)698AddMenuEntry(MENU_1, " ", false)699AddMenuEntry(MENU_1, "HILL TOP@@@@@@ 1", true)700AddMenuEntry(MENU_1, "2", false)701AddMenuEntry(MENU_1, " ", false)702AddMenuEntry(MENU_1, "MYSTIC CAVE@@@ 1", true)703AddMenuEntry(MENU_1, "2", false)704AddMenuEntry(MENU_1, " ", false)705AddMenuEntry(MENU_1, "OIL OCEAN@@@@@ 1", true)706AddMenuEntry(MENU_1, "2", false)707AddMenuEntry(MENU_1, " ", false)708709// Setup menu 2 (right column)710SetupMenu(MENU_2, 0, 3, 1)711712// Add its entries713AddMenuEntry(MENU_2, "METROPOLIS@@@@ 1", true)714AddMenuEntry(MENU_2, "2", false)715AddMenuEntry(MENU_2, "3", false)716AddMenuEntry(MENU_2, "SKY CHASE@@@@@@@", true)717AddMenuEntry(MENU_2, " ", false)718AddMenuEntry(MENU_2, " ", false)719AddMenuEntry(MENU_2, "WING FORTRESS@@@", true)720AddMenuEntry(MENU_2, " ", false)721AddMenuEntry(MENU_2, " ", false)722AddMenuEntry(MENU_2, "DEATH EGG@@@@@@@", true)723AddMenuEntry(MENU_2, " ", false)724AddMenuEntry(MENU_2, " ", false)725AddMenuEntry(MENU_2, "HIDDEN PALACE@@@", true)726AddMenuEntry(MENU_2, " ", 0)727AddMenuEntry(MENU_2, " ", 0)728AddMenuEntry(MENU_2, "SPECIAL STAGE@@@", true)729AddMenuEntry(MENU_2, " ", false)730AddMenuEntry(MENU_2, " ", false)731AddMenuEntry(MENU_2, "SOUND TEST@ *@@*", true)732733menu1.selection = 0734menu2.selection = -1735736// Not in the original, but origins compiler swaps the value of SPECIAL_STAGE to 2 (rather than 3 originally)737temp0 = 21738temp0 *= 6739temp0 += 2740SetTableValue(SPECIAL_STAGE, temp0, MenuControl_EntryTable)741end event742743744// ========================745// Editor Events746// ========================747748event RSDKDraw749DrawSprite(0)750end event751752753event RSDKLoad754LoadSpriteSheet("Global/Display.gif")755SpriteFrame(-16, -16, 32, 32, 1, 143)756757SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")758end event759760761