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

//-------Aliases-------//
private alias 9 : TYPE_DEBUGMODE
public alias saveRAM[295]: saved.mobile

// Function declarations
reserve function DebugMode_SpawnBlank
reserve function DebugMode_DrawBlank

// Static Values
public value DebugMode_ObjCount = 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
end table

public table DebugMode_DrawTable
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 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

public table DebugMode_SpawnTable
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	0, 0, 0, 0, 0, 0, 0, 0, 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_SpawnBlank
	temp0 = 0
end function


function DebugMode_DrawBlank
	DrawSprite(0)
end function


event ObjectMain
	if saved.mobile == 1
		CheckTouchRect(0, 96, screen.xcenter, screen.ysize)
		if checkResult > -1
			arrayPos0 = checkResult
			temp0 = touchscreen[arrayPos0].xpos
			temp0 -= 56
			temp1 = touchscreen[arrayPos0].ypos
			temp1 -= 184
			ATan2(temp2, temp0, temp1)
			temp2 += 16
			temp2 &= 255
			temp2 >>= 5
			switch temp2
			case 0
				inputDown.right = true
				break
			case 1
				inputDown.right = true
				inputDown.down = true
				break
			case 2
				inputDown.down = true
				break
			case 3
				inputDown.down = true
				inputDown.left = true
				break
			case 4
				inputDown.left = true
				break
			case 5
				inputDown.left = true
				inputDown.up = true
				break
			case 6
				inputDown.up = true
				break
			case 7
				inputDown.up = true
				inputDown.right = true
				break
			end switch
		end if
		temp0 = screen.xcenter
		temp0 -= 48
		temp1 = temp0
		temp1 += 96
		CheckTouchRect(temp0, 0, temp1, 56)

		if checkResult > -1
			arrayPos0 = checkResult
			if touchscreen[arrayPos0].xpos > screen.xcenter
				if touchJump == 0
					object.value17++
					if object.value17 >= DebugMode_ObjCount
						object.value17 = 0
					end if
				end if
				touchJump = true
			else
				if touchJump == 0
					object.value17--
					if object.value17 < 0
						object.value17 += DebugMode_ObjCount
					end if
				end if
				touchJump = true
			end if
		else
			CheckTouchRect(screen.xcenter, 96, screen.xsize, 240)
			switch checkResult
			case -1
				touchJump = 0
				break
			case 0
				inputDown.buttonC = true
				if touchJump == 0
					inputPress.buttonC |= inputDown.buttonC
				end if
				touchJump = inputDown.buttonC
				break
			end switch

		end if
		temp0 = screen.xsize
		temp0 -= 88
		CheckTouchRect(temp0, 0, screen.xsize, 40)
		if checkResult > -1
			inputPress.start = 1
		end if

		CheckTouchRect(0, 0, 112, 56)
		if checkResult > -1
			inputDown.buttonB = true
		end if
		if touchDebug == false
			inputPress.buttonB |= inputDown.buttonB
		end if
		touchDebug = inputDown.buttonB
	end if
	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 stage.playerListPos == 1
			object.type = TypeName[Tails Object]
		else
			object.type = TypeName[Player Object]
		end if
		if stage.playerListPos == 8
			object.type = TypeName[Tails Object]
		end if
		object.speed = 0
		object.xvel = 0
		object.yvel = 0
		object.state = 11
		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
	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
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 < 128
		SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypesTable)
		SetTableValue(DebugMode_DrawBlank, temp0, DebugMode_DrawTable)
		SetTableValue(DebugMode_SpawnBlank, temp0, DebugMode_SpawnTable)
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

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