// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Debug Mode Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 9 : TYPE_DEBUGMODE

// Priority Aliases
private alias 0 : PRIORITY_BOUNDS
private alias 1 : PRIORITY_ACTIVE
private alias 2 : PRIORITY_ALWAYS
private alias 3 : PRIORITY_XBOUNDS
private alias 4 : PRIORITY_XBOUNDS_DESTROY
private alias 5 : PRIORITY_INACTIVE
private alias 6 : PRIORITY_BOUNDS_SMALL
public alias 7 : PRIORITY_ACTIVE_SMALL		// these were plucked from latest s2 scripts because i can

// Function declarations
reserve function DebugMode_BlankSpawn
reserve function DebugMode_BlankDraw

// Static Values
public value DebugMode_ObjCount = 0;
public value DebugMode_ExitTimer = 0;

// Tables
public table DebugMode_TypesTable
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
end table


function DebugMode_BlankSpawn
	temp0 = 0
end function


function DebugMode_BlankDraw
	DrawSprite(0)
end function


event ObjectMain
	if DebugMode_ExitTimer == 0			
		temp0 = 0
		if inputDown.left == 1
			object.xpos -= object.yvel
			temp0 = 1
		end if
		if inputDown.right == 1
			object.xpos += object.yvel
			temp0 = 1
		end if
		if inputDown.up == 1
			object.ypos -= object.yvel
			temp0 = 1
		end if
		if inputDown.down == 1
			object.ypos += object.yvel
			temp0 = 1
		end if
		if temp0 == 1
			object.yvel += 0xC00
			if object.yvel > 0x100000
				object.yvel = 0x100000
			end if
		else
			object.yvel = 0
		end if
		object.value3 = 0
		object.value4 = 0
		if inputPress.buttonB == 1
			if DebugMode_ExitTimer == 0
				if stage.playerListPos == 1
					object.type = TypeName[Tails Object]
				else
					object.type = TypeName[Player Object]
				end if
				object.speed = 0
				object.xvel = 0
				object.yvel = 0
				object.state = PlayerObject_HandleAir
				object.animation = ANI_WALKING
				object.animationSpeed = 0
				object.frame = 0
				object.controlMode = 0
				object.drawOrder = -1
				object.value18 = 4
				object.interaction = 1
				object.tileCollisions = 1
				object.visible = 1
			end if
		else
			if inputPress.buttonA == 1
				object.value17++
				if object.value17 >= DebugMode_ObjCount
					object.value17 = 0
				end if
			end if
			if inputDown.buttonA == 1
				if inputPress.buttonC == 1
					object.value17--
					if object.value17 < 0
						object.value17 += DebugMode_ObjCount
					end if
				end if
			else
				if inputPress.buttonC == 1
					GetTableValue(temp0, object.value17, DebugMode_SpawnTable)
					CallFunction(temp0)
					object[tempObjectPos].priority = PRIORITY_XBOUNDS_DESTROY
				end if
			end if
		end if
	else
		DebugMode_ExitTimer += 8
		SetScreenFade(0, 0, 0, DebugMode_ExitTimer)
		if DebugMode_ExitTimer == 384
			starPostID = 0
			stage.activeList = PRESENTATION_STAGE
			stage.listPos = 5
			LoadStage()
		end if
	end if
end event


event ObjectDraw
	GetTableValue(object.type, object.value17, DebugMode_TypesTable)
	GetTableValue(temp0, object.value17, DebugMode_DrawTable)
	CallFunction(temp0)
	object.type = TypeName[Debug Mode]
end event


event ObjectStartup
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-8, -8, 16, 16, 188, 239)
	DebugMode_ObjCount = 0
	temp0 = 0
	while temp0 < 256
		SetTableValue(TypeName[DebugMode], temp0, DebugMode_TypesTable)
		SetTableValue(DebugMode_BlankDraw, temp0, DebugMode_DrawTable)
		SetTableValue(DebugMode_BlankSpawn, temp0, DebugMode_SpawnTable)
		temp0++
	loop
	DebugMode_ExitTimer = 0
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
