Path: blob/master/Sonic 1/Scripts/Special/DebugMode.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Debug Mode Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value10 : object.currentSelection121314// ========================15// Function Declarations16// ========================1718reserve function DebugMode_PlaceBlock19reserve function DebugMode_DummySpawn20reserve function DebugMode_DummyDraw21reserve function DebugMode_RemoveObject22reserve function DebugMode_RemoveIconDraw23reserve function DebugMode_LoadLayout24reserve function DebugMode_LoadIconDraw25reserve function DebugMode_SaveLayout26reserve function DebugMode_SaveIconDraw27reserve function DebugMode_ClrAllObjects28reserve function DebugMode_ClrIconDraw29reserve function DebugMode_FindBlockPos303132// ========================33// Static Values34// ========================3536public value DebugMode_ObjCount = 0373839// ========================40// Tables41// ========================4243// Three tables, to hold info about an object44// If an object is added to one table, it should be added to all the other three too4546// Holds all the object types47public table DebugMode_TypeTable[64]4849// Holds all the object Debug Draw functions50public table DebugMode_DrawTable[64]5152// Holds all the object Debug Spawn functions53public table DebugMode_SpawnTable[64]545556// ========================57// Function Definitions58// ========================5960// Shared by several functions to place (or remove) an object61public function DebugMode_PlaceBlock62temp0 = 06364// Loop through all objects65arrayPos0 = 0x2066while arrayPos0 < 0x42067if object[arrayPos0].type == TypeName[Blank Object]68temp0 = arrayPos069end if7071if temp6 == object[arrayPos0].xpos72if temp7 == object[arrayPos0].ypos73temp0 = arrayPos074arrayPos0 = 0x42075end if76end if77arrayPos0++78loop7980if temp0 != 081arrayPos0 = temp082ResetObjectEntity(temp0, temp5, temp4, temp6, temp7)83else84CreateTempObject(temp5, temp4, temp6, temp7)85arrayPos0 = object[tempObjectPos].entityPos86end if87end function888990public function DebugMode_DummySpawn91temp0 = 092end function939495public function DebugMode_DummyDraw96DrawSprite(0)97end function9899100public function DebugMode_RemoveObject101// Somewhat confusing, what it does here is places a blank object, which deletes the obj "under" it102temp5 = TypeName[Blank Object]103temp4 = 0104CallFunction(DebugMode_PlaceBlock)105end function106107108public function DebugMode_RemoveIconDraw109DrawSprite(2)110end function111112113public function DebugMode_LoadLayout114ReadSaveRAM()115116arrayPos0 = 32117arrayPos1 = 0x800118while arrayPos0 < 0x420119temp0 = saveRAM[arrayPos1]120temp0 &= 255121temp1 = saveRAM[arrayPos1]122temp1 >>= 8123arrayPos1++124temp2 = saveRAM[arrayPos1]125temp2 &= 0x7FF126temp2 *= 0x180000127temp2 += 0xC0000128temp3 = saveRAM[arrayPos1]129temp3 >>= 11130temp3 *= 0x180000131temp3 += 0xC0000132ResetObjectEntity(arrayPos0, temp0, temp1, temp2, temp3)133arrayPos1++134arrayPos0++135loop136end function137138139public function DebugMode_LoadIconDraw140DrawSprite(3)141end function142143144public function DebugMode_SaveLayout145arrayPos0 = 32146arrayPos1 = 0x800147while arrayPos0 < 0x420148temp2 = object[arrayPos0].propertyValue149temp2 <<= 8150temp2 += object[arrayPos0].type151saveRAM[arrayPos1] = temp2152arrayPos1++153temp0 = object[arrayPos0].xpos154temp0 /= 0x180000155temp1 = object[arrayPos0].ypos156temp1 /= 0x180000157if temp0 < 0158temp0 -= 0x180000159end if160if temp1 < 0161temp1 -= 0x180000162end if163temp1 <<= 11164temp0 += temp1165saveRAM[arrayPos1] = temp0166arrayPos1++167arrayPos0++168loop169170WriteSaveRAM()171end function172173174public function DebugMode_SaveIconDraw175DrawSprite(4)176end function177178179public function DebugMode_ClrAllObjects180temp0 = 0181182// Loop through all objects and delete them183arrayPos0 = 0x20184while arrayPos0 < 0x420185ResetObjectEntity(arrayPos0, TypeName[Blank Object], 0, 0, 0)186arrayPos0++187loop188end function189190191public function DebugMode_ClrIconDraw192DrawSprite(5)193end function194195196public function DebugMode_FindBlockPos197// Called by most Special Stage objects, in order to find their position based on the stage's current rotation198// Along with finding position, it also finds the block's angle199200temp2 = temp6201temp2 -= object[0].xpos202temp2 >>= 8203204temp3 = temp7205temp3 -= object[0].ypos206temp3 >>= 8207208Sin(temp4, Player_stageRotation)209210temp4 *= temp3211Cos(temp5, Player_stageRotation)212213temp5 *= temp2214temp0 = temp4215temp0 += temp5216temp0 >>= 1217temp0 += object[0].xpos218Cos(temp4, Player_stageRotation)219220temp4 *= temp3221Sin(temp5, Player_stageRotation)222223temp5 *= temp2224temp1 = temp4225temp1 -= temp5226temp1 >>= 1227temp1 += object[0].ypos228229object.rotation = 512230object.rotation -= Player_stageRotation231end function232233234// ========================235// Events236// ========================237238event ObjectUpdate239#platform: USE_STANDALONE240if options.touchControls == true241if object.controlMode == CONTROLMODE_P1242CheckTouchRect(0, 96, screen.xcenter, screen.ysize)243244if checkResult > -1245arrayPos0 = checkResult246temp0 = touchscreen[arrayPos0].xpos247temp0 -= saveRAM[39]248temp1 = touchscreen[arrayPos0].ypos249temp1 -= saveRAM[40]250251ATan2(temp2, temp0, temp1)252temp2 += 32253temp2 &= 255254temp2 >>= 6255256switch temp2257case 0258keyDown[0].right = true259break260261case 1262keyDown[0].down = true263break264265case 2266keyDown[0].left = true267break268269case 3270keyDown[0].up = true271break272end switch273end if274275temp0 = screen.xcenter276temp0 -= 48277278temp1 = temp0279temp1 += 96280281CheckTouchRect(temp0, 0, temp1, 56)282283if checkResult > -1284arrayPos0 = checkResult285286if touchscreen[arrayPos0].xpos > screen.xcenter287if touchJump == false288object.currentSelection++289if object.currentSelection >= DebugMode_ObjCount290object.currentSelection = 0291end if292end if293294touchJump = true295else296if touchJump == false297object.currentSelection--298if object.currentSelection < 0299object.currentSelection += DebugMode_ObjCount300end if301end if302303touchJump = true304end if305else306CheckTouchRect(screen.xcenter, 96, screen.xsize, 240)307308switch checkResult309case -1310touchJump = false311break312313case 0314keyDown[0].buttonC = true315if touchJump == 0316keyPress[0].buttonC |= keyDown[0].buttonC317end if318319touchJump = keyDown[0].buttonC320break321end switch322end if323324CheckTouchRect(0, 0, 112, 56)325326if checkResult > -1327keyDown[0].buttonB = true328end if329330if touchDebug == false331keyPress[0].buttonB |= keyDown[0].buttonB332end if333334touchDebug = keyDown[0].buttonB335temp0 = screen.xsize336temp0 -= 88337338CheckTouchRect(temp0, 0, screen.xsize, 40)339340if checkResult > -1341PlaySfx(SfxName[Menu Back], false)342engine.state = 5343end if344345if keyPress[0].start == true346PlaySfx(SfxName[Menu Back], false)347engine.state = 5348end if349end if350end if351#endplatform352353temp0 = false354if keyDown[0].left == true355object.xpos -= object.yvel356temp0 = true357end if358359if keyDown[0].right == true360object.xpos += object.yvel361temp0 = true362end if363364if keyDown[0].up == true365object.ypos -= object.yvel366temp0 = true367end if368369if keyDown[0].down == true370object.ypos += object.yvel371temp0 = true372end if373374if temp0 == true375object.yvel += 0xC00376if object.yvel > 0x100000377object.yvel = 0x100000378end if379else380object.yvel = 0381end if382383if keyPress[0].buttonB == true384object.type = TypeName[Player Object]385if stage.playerListPos == PLAYER_TAILS_A386object[+1].type = TypeName[Tails Object]387end if388object.speed = 0389object.xvel = 0390object.yvel = 0391object.frame = 0392object.controlMode = CONTROLMODE_P1393object.interaction = true394Player_rotateSpeed = 0395Player_rotateDir = 0396else397// Sonic Team forgot you can spawn 1UPs in special stages, so there's no checks for them in Origins, farm coins to your heart's content!398399if keyPress[0].buttonA == true400object.currentSelection++401if object.currentSelection >= DebugMode_ObjCount402object.currentSelection = 0403end if404end if405406if keyDown[0].buttonA == true407if keyPress[0].buttonC == true408object.currentSelection--409if object.currentSelection < 0410object.currentSelection += DebugMode_ObjCount411end if412end if413else414if keyPress[0].buttonC == true415GetTableValue(temp0, object.currentSelection, DebugMode_SpawnTable)416CallFunction(temp0)417object[tempObjectPos].priority = PRIORITY_XBOUNDS_DESTROY418end if419end if420end if421end event422423424event ObjectDraw425temp6 = object.xpos426temp7 = object.ypos427if temp6 < 0428temp6 -= 0x180000429end if430if temp7 < 0431temp7 -= 0x180000432end if433temp6 /= 0x180000434temp7 /= 0x180000435temp6 *= 0x180000436temp7 *= 0x180000437temp6 += 0xC0000438temp7 += 0xC0000439CallFunction(DebugMode_FindBlockPos)440DrawSpriteXY(1, temp0, temp1)441442// Temporarily switch to the selected object in order to draw the preview443GetTableValue(object.type, object.currentSelection, DebugMode_TypeTable)444GetTableValue(temp0, object.currentSelection, DebugMode_DrawTable)445CallFunction(temp0)446447// Switch back448object.type = TypeName[Debug Mode]449450// +/-451DrawSpriteScreenXY(6, screen.xcenter, 16)452DrawSpriteScreenXY(7, screen.xcenter, 16)453end event454455456event ObjectStartup457LoadSpriteSheet("Special/Objects.gif")458459// Editor sprite frames460SpriteFrame(-12, -12, 24, 24, 251, 176) // life icon - #0461SpriteFrame(-12, -12, 24, 24, 131, 454) // selection box - #1462SpriteFrame(-12, -12, 24, 24, 131, 479) // delete icon - #2463SpriteFrame(-12, -12, 24, 24, 455, 486) // load icon - #3464SpriteFrame(-12, -12, 24, 24, 480, 486) // save icon - #4465SpriteFrame(-12, -12, 24, 24, 308, 376) // clear icon - #5466SpriteFrame(-16, 0, 8, 8, 339, 390) // - icon - #6467SpriteFrame(8, 0, 8, 8, 348, 390) // + icon - #7468469DebugMode_ObjCount = 0470471// Fill the list up with dummy entries472temp0 = 0473while temp0 < 64474SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypeTable)475SetTableValue(DebugMode_DummyDraw, temp0, DebugMode_DrawTable)476SetTableValue(DebugMode_DummySpawn, temp0, DebugMode_SpawnTable)477temp0++478loop479480// Add the object deleter as an entry481SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypeTable)482SetTableValue(DebugMode_RemoveIconDraw, DebugMode_ObjCount, DebugMode_DrawTable)483SetTableValue(DebugMode_RemoveObject, DebugMode_ObjCount, DebugMode_SpawnTable)484DebugMode_ObjCount++485486// Is the player in the custom special stage bulder scene?487if stage.actNum == 8488// Load saved stage489SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypeTable)490SetTableValue(DebugMode_LoadIconDraw, DebugMode_ObjCount, DebugMode_DrawTable)491SetTableValue(DebugMode_LoadLayout, DebugMode_ObjCount, DebugMode_SpawnTable)492DebugMode_ObjCount++493494// Save current stage495SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypeTable)496SetTableValue(DebugMode_SaveIconDraw, DebugMode_ObjCount, DebugMode_DrawTable)497SetTableValue(DebugMode_SaveLayout, DebugMode_ObjCount, DebugMode_SpawnTable)498DebugMode_ObjCount++499500// Clear current stage501SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypeTable)502SetTableValue(DebugMode_ClrIconDraw, DebugMode_ObjCount, DebugMode_DrawTable)503SetTableValue(DebugMode_ClrAllObjects, DebugMode_ObjCount, DebugMode_SpawnTable)504DebugMode_ObjCount++505end if506end event507508509// ========================510// Editor Events511// ========================512513event RSDKDraw514DrawSprite(0)515end event516517518event RSDKLoad519LoadSpriteSheet("Global/Display.gif")520SpriteFrame(-16, -16, 32, 32, 1, 143)521522SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")523end event524525526